Class: Distil::Configurable::ConfigDsl
- Inherits:
-
Object
- Object
- Distil::Configurable::ConfigDsl
- Defined in:
- lib/distil/configurable.rb
Instance Method Summary collapse
-
#initialize(hash) ⇒ ConfigDsl
constructor
A new instance of ConfigDsl.
- #used?(key) ⇒ Boolean
- #with(key) ⇒ Object
- #with_each(key) ⇒ Object
Constructor Details
#initialize(hash) ⇒ ConfigDsl
Returns a new instance of ConfigDsl.
17 18 19 20 |
# File 'lib/distil/configurable.rb', line 17 def initialize(hash) @hash= hash @used= Set.new end |
Instance Method Details
#used?(key) ⇒ Boolean
47 48 49 |
# File 'lib/distil/configurable.rb', line 47 def used?(key) @used.include?(key.to_s) end |
#with(key) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/distil/configurable.rb', line 36 def with(key) case when @hash.include?(key.to_sym) yield @hash[key.to_sym] when @hash.include?(key.to_s) yield @hash[key.to_s] else return end @used << key.to_s end |
#with_each(key) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/distil/configurable.rb', line 22 def with_each(key) case when @hash.include?(key.to_sym) value= @hash[key.to_sym] when @hash.include?(key.to_s) value= @hash[key.to_s] else return end value= value.split(",").map { |s| s.strip } if value.is_a?(String) value.each { |v| yield v } @used << key.to_s end |