Class: Rapid::Setting::Base
- Inherits:
-
Object
- Object
- Rapid::Setting::Base
- Defined in:
- lib/rapid/setting/base.rb
Direct Known Subclasses
BooleanSetting, IntegerSetting, Namespace::Base, StringSetting
Instance Attribute Summary collapse
-
#default_value ⇒ Object
readonly
Returns the value of attribute default_value.
-
#full_name ⇒ Object
readonly
Returns the value of attribute full_name.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
Instance Method Summary collapse
- #define_helpers(klass) ⇒ Object
-
#initialize(name, options = {}) ⇒ Base
constructor
A new instance of Base.
- #load(value) ⇒ Object
Constructor Details
#initialize(name, options = {}) ⇒ Base
Returns a new instance of Base.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rapid/setting/base.rb', line 8 def initialize name, = {} @name = name.to_sym if name @namespace = [:namespace] @default_value = [:default] if @namespace @full_name = "#{@namespace.full_name}.#{name}" elsif @name @full_name = name.to_s end if Rapid::Settings.reserved_name? @name raise ArgumentError.new("#{@name} is a reserved setting name") end if @namespace @namespace.send :add_child, self end end |
Instance Attribute Details
#default_value ⇒ Object (readonly)
Returns the value of attribute default_value.
6 7 8 |
# File 'lib/rapid/setting/base.rb', line 6 def default_value @default_value end |
#full_name ⇒ Object (readonly)
Returns the value of attribute full_name.
6 7 8 |
# File 'lib/rapid/setting/base.rb', line 6 def full_name @full_name end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/rapid/setting/base.rb', line 6 def name @name end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
6 7 8 |
# File 'lib/rapid/setting/base.rb', line 6 def namespace @namespace end |
Instance Method Details
#define_helpers(klass) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rapid/setting/base.rb', line 32 def define_helpers klass name = self.name getter = name setter = "#{name}=" klass.class_eval do define_method getter do self[name] end define_method "#{getter}?" do self[name] != nil end define_method setter do |value| self[name] = value end end true end |
#load(value) ⇒ Object
28 29 30 |
# File 'lib/rapid/setting/base.rb', line 28 def load value raise "Subclass should override this method" end |