Module: Card::Setting

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",
  :pointer       => "Pointer",
  :editing_cue   => "Editing cues",
  :event         => "Events",
  :other         => "Other"
}
@@groups =
@@group_names.keys.each_with_object({}) { |key, groups| groups[key] = [] }
@@user_specific =
::Set.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#codenameObject

Let M = Card::Setting (module)

E = Card::Set::Self::Create (module extended with M)
O = Card["*create"]         (object)


11
12
13
# File 'mod/04_settings/lib/card/setting.rb', line 11

def codename
  @codename
end

Class Method Details

.extended(host_class) ⇒ Object



13
14
15
# File 'mod/04_settings/lib/card/setting.rb', line 13

def self.extended(host_class)
   host_class.mattr_accessor :restricted_to_type, :rule_type_editable  # accessible in E and O
end

.user_specific?(codename) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'mod/04_settings/lib/card/setting.rb', line 29

def self.user_specific? codename
  @@user_specific.include? codename
end

Instance Method Details

#applies_to_cardtype(type_id) ⇒ Object



63
64
65
# File 'mod/04_settings/lib/card/setting.rb', line 63

def applies_to_cardtype type_id
  !self.restricted_to_type or self.restricted_to_type.include? type_id
end

#setting_opts(opts) ⇒ Object

usage: setting_opts :group => :permission | :event | …

:position           => <Fixnum> (starting at 1, default: add to end)
:rule_type_editable => true | false (default: false)
:restricted_to_type => <cardtype> | [ <cardtype>, ...]


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'mod/04_settings/lib/card/setting.rb', line 42

def setting_opts opts
  group = opts[:group] || :other
  @@groups[group] ||= []
  if opts[:position]
    if @@groups[group][opts[:position]-1]
      @@groups[group].insert(opts[:position]-1, self)
    else
      @@groups[group][opts[:position]-1] = self
    end
  else
    @@groups[group] << self
  end

  @codename = opts[:codename] || self.name.match(/::(\w+)$/)[1].underscore.to_sym
  self.rule_type_editable = opts[:rule_type_editable]
  self.restricted_to_type = opts[:restricted_to_type] ? ::Set.new([opts[:restricted_to_type]].flatten.map{ |cardtype| to_type_id(cardtype) }) : false
  if opts[:user_specific]
    @@user_specific << @codename
  end
end

#to_type_id(type) ⇒ Object



33
34
35
# File 'mod/04_settings/lib/card/setting.rb', line 33

def to_type_id type
  type.is_a?(Fixnum) ? type : Card::Codename[type]
end