Module: Card::Setting
- Defined in:
- card/lib/card/setting.rb
Overview
Used to extend setting modules like Card::Set::Self::Create in the settings mod
Constant Summary collapse
- SETTING_OPTIONS =
%i[ restricted_to_type rule_type_editable short_help_text raw_help_text applies ].freeze
Instance Attribute Summary collapse
-
#codename ⇒ Object
Let M = Card::Setting (module) E = Card::Set::Self::Create (module extended with M) O = Card[‘*create’] (object) accessible in E.
Class Method Summary collapse
Instance Method Summary collapse
-
#applies_to_cardtype(type_id, prototype = nil) ⇒ Object
-
#applies_to_prototype?(prototype) ⇒ Boolean
-
#register_setting(opts) ⇒ Object
usage: setting_opts group: :permission :event …
Instance Attribute Details
#codename ⇒ Object
Let M = Card::Setting (module) E = Card::Set::Self::Create (module extended with M) O = Card[‘*create’] (object) accessible in E
11 12 13 |
# File 'card/lib/card/setting.rb', line 11 def codename @codename end |
Class Method Details
.codenames ⇒ Object
36 37 38 |
# File 'card/lib/card/setting.rb', line 36 def codenames groups.values.flatten.compact.map(&:codename) end |
.extended(host_class) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'card/lib/card/setting.rb', line 25 def extended host_class # accessible in E and O host_class.mattr_accessor(*SETTING_OPTIONS) setting_class_name = host_class.to_s.split("::").last host_class.ensure_set { "Card::Set::Right::#{setting_class_name}" } host_class.mattr_accessor :right_set host_class.right_set = Card::Set::Right.const_get(setting_class_name) host_class.right_set.mattr_accessor :raw_help_text end |
.preference?(codename) ⇒ Boolean
40 41 42 |
# File 'card/lib/card/setting.rb', line 40 def preference? codename preferences.include? codename end |
Instance Method Details
#applies_to_cardtype(type_id, prototype = nil) ⇒ Object
74 75 76 77 |
# File 'card/lib/card/setting.rb', line 74 def applies_to_cardtype type_id, prototype=nil (!restricted_to_type || restricted_to_type.include?(type_id)) && (!prototype || applies_to_prototype?(prototype)) end |
#applies_to_prototype?(prototype) ⇒ Boolean
79 80 81 82 83 |
# File 'card/lib/card/setting.rb', line 79 def applies_to_prototype? prototype return true unless applies applies.call(prototype) end |
#register_setting(opts) ⇒ Object
usage:
setting_opts group: :permission | :event | …
position:
63 64 65 66 67 68 69 70 71 72 |
# File 'card/lib/card/setting.rb', line 63 def register_setting opts group = opts[:group] || :other Card::Setting.groups[group] ||= [] set_position group, opts[:position] register_preference opts[:codename], opts[:preference] standard_setting_opts opts, :rule_type_editable, :short_help_text, :applies restrict_setting_to_type opts[:restricted_to_type] help_text_for_setting opts[:help_text] end |