Module: Card::Setting
- Included in:
- Card::Set::Self::Accountable, Card::Set::Self::AddHelp, Card::Set::Self::Autoname, Card::Set::Self::Captcha, Card::Set::Self::Create, Card::Set::Self::CsvStructure, Card::Set::Self::Default, Card::Set::Self::DefaultHtmlView, Card::Set::Self::Delete, Card::Set::Self::Follow, Card::Set::Self::FollowFields, Card::Set::Self::Head, Card::Set::Self::Help, Card::Set::Self::Input, Card::Set::Self::Layout, Card::Set::Self::OnCreate, Card::Set::Self::OnDelete, Card::Set::Self::OnUpdate, Card::Set::Self::Options, Card::Set::Self::OptionsLabel, Card::Set::Self::Read, Card::Set::Self::Script, Card::Set::Self::Structure, Card::Set::Self::Style, Card::Set::Self::TableOfContents, Card::Set::Self::Thanks, Card::Set::Self::Update
- Defined in:
- mod/settings/lib/card/setting.rb
Overview
Used to extend setting modules like Card::Set::Self::Create in the settings mod
Constant Summary collapse
- @@group_names =
{ templating: "Templating", permission: "Permissions", webpage: "Webpage", editing: "Editing", event: "Events", other: "Other", config: "Config" }
- @@groups =
@@group_names.keys.each_with_object({}) do |key, groups| groups[key] = [] end
- @@user_specific =
::Set.new
Instance Attribute Summary collapse
-
#codename ⇒ Object
Let M = Card::Setting (module) E = Card::Set::Self::Create (module extended with M) O = Card'*create' accessible in E.
Class Method Summary collapse
Instance Method Summary collapse
- #applies_to_cardtype(type_id, prototype = nil) ⇒ Object
- #applies_to_prototype?(prototype) ⇒ Boolean
- #set_position(group, pos) ⇒ Object
-
#setting_opts(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' accessible in E
11 12 13 |
# File 'mod/settings/lib/card/setting.rb', line 11 def codename @codename end |
Class Method Details
.codenames ⇒ Object
24 25 26 |
# File 'mod/settings/lib/card/setting.rb', line 24 def self.codenames Card::Setting.groups.values.flatten.compact.map(&:codename) end |
.extended(host_class) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'mod/settings/lib/card/setting.rb', line 14 def self.extended host_class # accessible in E and O host_class.mattr_accessor :restricted_to_type, :rule_type_editable, :short_help_text, :raw_help_text, :right_set, :applies setting_class_name = host_class.to_s.split("::").last host_class.ensure_set { "Card::Set::Right::#{setting_class_name}" } host_class.right_set = Card::Set::Right.const_get(setting_class_name) host_class.right_set.mattr_accessor :raw_help_text end |
.user_specific?(codename) ⇒ Boolean
42 43 44 |
# File 'mod/settings/lib/card/setting.rb', line 42 def self.user_specific? codename @@user_specific.include? codename end |
Instance Method Details
#applies_to_cardtype(type_id, prototype = nil) ⇒ Object
79 80 81 82 |
# File 'mod/settings/lib/card/setting.rb', line 79 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
84 85 86 87 |
# File 'mod/settings/lib/card/setting.rb', line 84 def applies_to_prototype? prototype return true unless applies applies.call(prototype) end |
#set_position(group, pos) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 |
# File 'mod/settings/lib/card/setting.rb', line 67 def set_position group, pos if pos if @@groups[group][pos - 1] @@groups[group].insert(pos - 1, self) else @@groups[group][pos - 1] = self end else @@groups[group] << self end end |
#setting_opts(opts) ⇒ Object
usage:
setting_opts group: :permission | :event | ...
position:
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'mod/settings/lib/card/setting.rb', line 51 def setting_opts opts group = opts[:group] || :other @@groups[group] ||= [] set_position group, opts[:position] @codename = opts[:codename] || name.match(/::(\w+)$/)[1].underscore.to_sym self.rule_type_editable = opts[:rule_type_editable] self.restricted_to_type = permitted_type_ids opts[:restricted_to_type] self.short_help_text = opts[:short_help_text] self.applies = opts[:applies] right_set.raw_help_text = self.raw_help_text = opts[:help_text] return unless opts[:user_specific] @@user_specific << @codename end |