diff options
author | Michael Bleigh <michael@intridea.com> | 2010-01-14 12:14:41 -0500 |
---|---|---|
committer | Michael Bleigh <michael@intridea.com> | 2010-01-14 12:14:41 -0500 |
commit | bbb9df0d527ff9e913b957abaa67a92d747bbb36 (patch) | |
tree | 5ca69b40f246461dbfd07ce2386ff7b978da5951 | |
parent | 7f382b26a7774af704e45ad44afd341ce4c0a01e (diff) | |
parent | 81ec5006cfe2d4c0adc7cecf9940eb6dbb8cbe39 (diff) | |
download | hashie-bbb9df0d527ff9e913b957abaa67a92d747bbb36.tar.gz |
Merge branch 'master' of github.com:intridea/hashie
-rw-r--r-- | lib/hashie/dash.rb | 22 | ||||
-rw-r--r-- | spec/hashie/dash_spec.rb | 10 |
2 files changed, 26 insertions, 6 deletions
diff --git a/lib/hashie/dash.rb b/lib/hashie/dash.rb index 3d73090..6d4e6b5 100644 --- a/lib/hashie/dash.rb +++ b/lib/hashie/dash.rb @@ -26,8 +26,8 @@ module Hashie def self.property(property_name, options = {}) property_name = property_name.to_sym - (@@properties ||= []) << property_name - (@@defaults ||= {})[property_name] = options.delete(:default) + (@properties ||= []) << property_name + (@defaults ||= {})[property_name] = options.delete(:default) class_eval <<-RUBY def #{property_name} @@ -43,7 +43,14 @@ module Hashie # Get a String array of the currently defined # properties on this Dash. def self.properties - @@properties.collect{|p| p.to_s} + properties = [] + ancestors.each do |elder| + if elder.instance_variable_defined?("@properties") + properties << elder.instance_variable_get("@properties") + end + end + + properties.flatten.map{|p| p.to_s} end # Check to see if the specified property has already been @@ -54,7 +61,14 @@ module Hashie # The default values that have been set for this Dash def self.defaults - @@defaults + properties = {} + ancestors.each do |elder| + if elder.instance_variable_defined?("@defaults") + properties.merge! elder.instance_variable_get("@defaults") + end + end + + properties end # You may initialize a Dash with an attributes hash diff --git a/spec/hashie/dash_spec.rb b/spec/hashie/dash_spec.rb index c800681..b7971f9 100644 --- a/spec/hashie/dash_spec.rb +++ b/spec/hashie/dash_spec.rb @@ -7,6 +7,7 @@ class DashTest < Hashie::Dash end class Subclassed < DashTest + property :last_name end describe Hashie::Dash do @@ -84,14 +85,19 @@ end describe Subclassed do it "should inherit all properties from DashTest" do - Subclassed.properties.size.should == 5 + Subclassed.properties.size.should == 6 end it "should inherit all defaults from DashTest" do - Subclassed.defaults.size.should == 5 + Subclassed.defaults.size.should == 6 end it "should init without raising" do lambda { Subclassed.new }.should_not raise_error + lambda { Subclassed.new(:first_name => 'Michael') }.should_not raise_error + end + + it "should share defaults from DashTest" do + Subclassed.new.count.should == 0 end end
\ No newline at end of file |