Module: Card::Set::All::Rules

Extended by:
Card::Set
Defined in:
card/tmpsets/set/mod002-core/all/rules.rb

Overview

Set: All cards (Rules)

Constant Summary

Constants included from Helpers

Helpers::SET_PATTERN_TEST_REGEXP

Constants included from Event::Api

Event::Api::OPTIONS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Card::Set

reset_modules

Methods included from I18nScope

#mod_name, #scope

Methods included from Loader

#clean_empty_module_from_hash, #clean_empty_modules, #extended, #process_base_modules, #register_set

Methods included from Helpers

#method_missing, #num_set_parts, #pattern_code, #respond_to_missing?, #set_name_parts, #shortname, #underscore

Methods included from Card::Set::AdvancedApi

#attachment, #define_set_from_error, #ensure_set, #setting_opts, #stage_method

Methods included from Format

#before, #format, layout_method_name, #view, view_method_name, view_setting_method_name, wrapper_method_name

Methods included from Inheritance

#include_set, #include_set_formats

Methods included from Basket

#abstract_basket, #add_to_basket, #basket, #unshift_basket

Methods included from Trait

#card_accessor, #card_reader, #card_writer, #require_field

Methods included from Event::Api

#event

Class Method Details

.source_locationObject



7
# File 'card/tmpsets/set/mod002-core/all/rules.rb', line 7

def self.source_location; "/Users/ethan/dev/decko/gem/card/mod/core/set/all/rules.rb"; end

Instance Method Details

#is_preference?Boolean

Returns:

  • (Boolean)


46
47
48
49
50
51
52
53
54
# File 'card/tmpsets/set/mod002-core/all/rules.rb', line 46

def is_preference?
  name.parts.length > 2 &&
    (r = right(skip_modules: true)) &&
    r.type_id == SettingID &&
    (set = self[0..-3, skip_modules: true]) &&
    set.type_id == SetID &&
    (user = self[-2, skip_modules: true]) &&
    (user.type_id == UserID || user.codename == :all)
end

#is_rule?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'card/tmpsets/set/mod002-core/all/rules.rb', line 35

def is_rule?
  is_standard_rule? || is_preference?
end

#is_standard_rule?Boolean

Returns:

  • (Boolean)


39
40
41
42
43
44
# File 'card/tmpsets/set/mod002-core/all/rules.rb', line 39

def is_standard_rule?
  (r = right(skip_modules: true)) &&
    r.type_id == SettingID &&
    (l = left(skip_modules: true)) &&
    l.type_id == SetID
end

#preference(setting_code, user = nil) ⇒ Object



20
21
22
# File 'card/tmpsets/set/mod002-core/all/rules.rb', line 20

def preference setting_code, user=nil
  preference_card(setting_code, user, skip_modules: true)&.db_content
end

#preference_card(setting_code, user = nil, options = {}) ⇒ Object



24
25
26
# File 'card/tmpsets/set/mod002-core/all/rules.rb', line 24

def preference_card setting_code, user=nil, options={}
  Card.fetch preference_card_id(setting_code, user), options
end

#preference_card_id(setting_code, user = nil) ⇒ Object



28
29
30
31
32
33
# File 'card/tmpsets/set/mod002-core/all/rules.rb', line 28

def preference_card_id setting_code, user=nil
  return unless (user_id = preference_user_id user)
  rule_id_lookup Card::Rule.preference_cache,
                 "#{setting_code}+#{user_id}",
                 "#{setting_code}+#{AllID}"
end

FIXME: move to a better place (if still needed) and use codenames



57
58
59
60
61
62
63
64
65
66
67
# File 'card/tmpsets/set/mod002-core/all/rules.rb', line 57

def related_sets with_self=false
  # refers to sets that users may configure from the current card -
  # NOT to sets to which the current card belongs

  sets = []
  sets << ["#{name}+*self", Card::Set::Self.label(name)] if with_self
  if known? && name.simple?
    sets << ["#{name}+*right", Card::Set::Right.label(name)]
  end
  sets
end

#rule(setting_code) ⇒ Object



8
9
10
# File 'card/tmpsets/set/mod002-core/all/rules.rb', line 8

def rule setting_code
  rule_card(setting_code, skip_modules: true)&.db_content
end

#rule_card(setting_code, options = {}) ⇒ Object



12
13
14
# File 'card/tmpsets/set/mod002-core/all/rules.rb', line 12

def rule_card setting_code, options={}
  Card.fetch rule_card_id(setting_code), options
end

#rule_card_id(setting_code) ⇒ Object



16
17
18
# File 'card/tmpsets/set/mod002-core/all/rules.rb', line 16

def rule_card_id setting_code
  rule_id_lookup Card::Rule.rule_cache, setting_code
end