Class: Alf::Support::Config
- Inherits:
-
Object
- Object
- Alf::Support::Config
- Extended by:
- ClassMethods
- Defined in:
- lib/alf-support/alf/support/config.rb
Direct Known Subclasses
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#[](option) ⇒ Object
Returns the value of an option.
-
#[]=(option, value) ⇒ Object
Sets the value of an option.
-
#dup ⇒ Object
Duplicates this configuration as well as all option values.
-
#freeze ⇒ Object
Freeze this configuration as well as all option values.
-
#initialize(h = {}) {|_self| ... } ⇒ Config
constructor
Creates a default options instance.
-
#merge(h) ⇒ Object
Merge with another options from a hash.
Methods included from ClassMethods
delegation_methods, each_option, getter_name, helpers, ivar_name, option, option_get, option_set, options, setter_name
Constructor Details
#initialize(h = {}) {|_self| ... } ⇒ Config
Creates a default options instance
74 75 76 77 |
# File 'lib/alf-support/alf/support/config.rb', line 74 def initialize(h = {}) (h) yield(self) if block_given? end |
Instance Method Details
#[](option) ⇒ Object
Returns the value of an option
80 81 82 |
# File 'lib/alf-support/alf/support/config.rb', line 80 def [](option) self.class.option_get(self, option) end |
#[]=(option, value) ⇒ Object
Sets the value of an option
85 86 87 |
# File 'lib/alf-support/alf/support/config.rb', line 85 def []=(option, value) self.class.option_set(self, option, value) end |
#dup ⇒ Object
Duplicates this configuration as well as all option values
95 96 97 98 99 100 101 102 103 104 |
# File 'lib/alf-support/alf/support/config.rb', line 95 def dup super.tap do |c| self.class.each_option do |name,_,default| ivar_name = self.class.ivar_name(name) if instance_variable_defined?(ivar_name) || !default.is_a?(Proc) c[name] = (self[name].dup rescue self[name]) end end end end |
#freeze ⇒ Object
Freeze this configuration as well as all option values
107 108 109 110 111 112 113 |
# File 'lib/alf-support/alf/support/config.rb', line 107 def freeze super self.class.each_option do |name,_,_| self[name].freeze end self end |
#merge(h) ⇒ Object
Merge with another options from a hash
90 91 92 |
# File 'lib/alf-support/alf/support/config.rb', line 90 def merge(h) dup.(h) end |