Class: Configarrr::Base
- Inherits:
-
Object
- Object
- Configarrr::Base
- Defined in:
- lib/configarrr/base.rb
Class Method Summary collapse
Instance Method Summary collapse
- #configure(&block) ⇒ Object
-
#initialize(options = {}) ⇒ Base
constructor
A new instance of Base.
- #set(key, value = self) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Base
Returns a new instance of Base.
3 4 5 6 |
# File 'lib/configarrr/base.rb', line 3 def initialize( = {}) @keys = [] () end |
Class Method Details
.configure(options = {}, &block) ⇒ Object
8 9 10 11 12 |
# File 'lib/configarrr/base.rb', line 8 def self.configure( = {}, &block) config = new() config.configure(&block) config end |
Instance Method Details
#configure(&block) ⇒ Object
14 15 16 |
# File 'lib/configarrr/base.rb', line 14 def configure(&block) instance_eval(&block) end |
#set(key, value = self) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/configarrr/base.rb', line 18 def set(key, value=self) if value.kind_of?(Proc) (key, &value) ("#{key}?") { !!__send__(key) } ("#{key}=") { |val| set(key, Proc.new{val}) } @keys << key elsif value == self && key.is_a?(Hash) key.to_hash.each { |k,v| set(k, v) } elsif respond_to?("#{key}=") __send__ "#{key}=", value @keys << key else set key, Proc.new{value} end self end |
#to_hash ⇒ Object
35 36 37 38 39 40 |
# File 'lib/configarrr/base.rb', line 35 def to_hash @keys.inject({}) do |hash, key| hash[key] = __send__ "#{key}" hash end end |