lib/mattock/configurable.rb in mattock-0.2.11 vs lib/mattock/configurable.rb in mattock-0.2.12

- old
+ new

@@ -89,10 +89,24 @@ #shrug it off end end end + def to_hash(obj) + hash = if Configurable > superclass + superclass.to_hash(obj) + else + {} + end + hash.merge( Hash[default_values.keys.zip(default_values.keys.map{|key| + begin + obj.__send__(key) + rescue NoMethodError + end + }).to_a]) + end + #Creates an anonymous Configurable - useful in complex setups for nested #settings #@example SSH options # setting :ssh => nested(:username => "me", :password => nil) def nested(hash=nil) @@ -147,9 +161,13 @@ extend ClassMethods def copy_settings_to(other) self.class.copy_settings(self, other) self + end + + def to_hash + self.class.to_hash(self) end #Call during initialize to set default values on settings - if you're using #Configurable outside of Mattock, be sure this gets called. def setup_defaults