Class: Rapid::Setting::Namespace::Base
- Defined in:
- lib/rapid/setting/namespace/base.rb
Instance Attribute Summary collapse
-
#instance_class ⇒ Object
Returns the value of attribute instance_class.
Attributes inherited from Base
#default_value, #full_name, #name, #namespace
Instance Method Summary collapse
- #[](key) ⇒ Object
- #define_helpers(klass) ⇒ Object
-
#initialize(name, options = {}) ⇒ Base
constructor
A new instance of Base.
- #namespaces ⇒ Object
- #scalars ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(name, options = {}) ⇒ Base
Returns a new instance of Base.
9 10 11 12 13 14 15 16 |
# File 'lib/rapid/setting/namespace/base.rb', line 9 def initialize name, = {} super name, @delegate = HashWithIndifferentAccess.new {} # class option isn't provided for the root namespace klass = [:class] @instance_class = define_instance_class klass if klass end |
Instance Attribute Details
#instance_class ⇒ Object
Returns the value of attribute instance_class.
7 8 9 |
# File 'lib/rapid/setting/namespace/base.rb', line 7 def instance_class @instance_class end |
Instance Method Details
#[](key) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rapid/setting/namespace/base.rb', line 30 def [] key namespace_name, child_name = Rapid::Settings.extract_nested_namespace(key) if namespace_name namespace = @delegate[namespace_name] namespace[child_name] if namespace else @delegate[key] end end |
#define_helpers(klass) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rapid/setting/namespace/base.rb', line 41 def define_helpers klass super name = self.name getter = self.name klass.class_eval do define_method "#{getter}?" do val = self[name] val != nil && val.on? end end true end |