Class: Distil::Configurable
- Inherits:
-
Object
- Object
- Distil::Configurable
- Defined in:
- lib/distil/configurable.rb
Defined Under Namespace
Classes: ConfigDsl
Constant Summary collapse
- @@config_aliases =
{}
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.alias_config_key(original, key_alias) ⇒ Object
6 7 8 |
# File 'lib/distil/configurable.rb', line 6 def self.alias_config_key(original, key_alias) @@config_aliases[key_alias.to_s]= original.to_s end |
Instance Method Details
#configure_with(hash) {|dsl| ... } ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/distil/configurable.rb', line 53 def configure_with(hash) new_hash= {} hash.each { |key, value| new_hash[key_for_alias(key)]= value } dsl= ConfigDsl.new(new_hash) yield dsl if block_given? new_hash.each { |key, value| next if dsl.used?(key.to_s) key= key_for_alias(key) case when self.respond_to?("#{key}=") self.send "#{key}=", value when self.respond_to?(key) && 0!=self.method(key).arity self.send key, value else self.instance_variable_set("@#{key}", value) end } end |
#key_for_alias(key_alias) ⇒ Object
10 11 12 13 |
# File 'lib/distil/configurable.rb', line 10 def key_for_alias(key_alias) key_alias= key_alias.to_s.gsub("-", "_").gsub(" ", "_") @@config_aliases[key_alias] || key_alias end |