hashie 0.1.6 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/hashie.gemspec +2 -2
- data/lib/hashie/dash.rb +18 -4
- data/spec/hashie/dash_spec.rb +8 -2
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.8
|
data/hashie.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{hashie}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.8"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Michael Bleigh"]
|
12
|
-
s.date = %q{2010-01-
|
12
|
+
s.date = %q{2010-01-14}
|
13
13
|
s.description = %q{Hashie is a small collection of tools that make hashes more powerful. Currently includes Mash (Mocking Hash) and Dash (Discrete Hash).}
|
14
14
|
s.email = %q{michael@intridea.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/hashie/dash.rb
CHANGED
@@ -26,8 +26,8 @@ module Hashie
|
|
26
26
|
def self.property(property_name, options = {})
|
27
27
|
property_name = property_name.to_sym
|
28
28
|
|
29
|
-
(
|
30
|
-
(
|
29
|
+
(@properties ||= []) << property_name
|
30
|
+
(@defaults ||= {})[property_name] = options.delete(:default)
|
31
31
|
|
32
32
|
class_eval <<-RUBY
|
33
33
|
def #{property_name}
|
@@ -43,7 +43,14 @@ module Hashie
|
|
43
43
|
# Get a String array of the currently defined
|
44
44
|
# properties on this Dash.
|
45
45
|
def self.properties
|
46
|
-
|
46
|
+
properties = []
|
47
|
+
ancestors.each do |elder|
|
48
|
+
if elder.instance_variable_defined?("@properties")
|
49
|
+
properties << elder.instance_variable_get("@properties")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
properties.flatten.map{|p| p.to_s}
|
47
54
|
end
|
48
55
|
|
49
56
|
# Check to see if the specified property has already been
|
@@ -54,7 +61,14 @@ module Hashie
|
|
54
61
|
|
55
62
|
# The default values that have been set for this Dash
|
56
63
|
def self.defaults
|
57
|
-
|
64
|
+
properties = {}
|
65
|
+
ancestors.each do |elder|
|
66
|
+
if elder.instance_variable_defined?("@defaults")
|
67
|
+
properties.merge! elder.instance_variable_get("@defaults")
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
properties
|
58
72
|
end
|
59
73
|
|
60
74
|
# You may initialize a Dash with an attributes hash
|
data/spec/hashie/dash_spec.rb
CHANGED
@@ -7,6 +7,7 @@ class DashTest < Hashie::Dash
|
|
7
7
|
end
|
8
8
|
|
9
9
|
class Subclassed < DashTest
|
10
|
+
property :last_name
|
10
11
|
end
|
11
12
|
|
12
13
|
describe Hashie::Dash do
|
@@ -84,14 +85,19 @@ end
|
|
84
85
|
|
85
86
|
describe Subclassed do
|
86
87
|
it "should inherit all properties from DashTest" do
|
87
|
-
Subclassed.properties.size.should ==
|
88
|
+
Subclassed.properties.size.should == 6
|
88
89
|
end
|
89
90
|
|
90
91
|
it "should inherit all defaults from DashTest" do
|
91
|
-
Subclassed.defaults.size.should ==
|
92
|
+
Subclassed.defaults.size.should == 6
|
92
93
|
end
|
93
94
|
|
94
95
|
it "should init without raising" do
|
95
96
|
lambda { Subclassed.new }.should_not raise_error
|
97
|
+
lambda { Subclassed.new(:first_name => 'Michael') }.should_not raise_error
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should share defaults from DashTest" do
|
101
|
+
Subclassed.new.count.should == 0
|
96
102
|
end
|
97
103
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hashie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Bleigh
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-14 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|