hash_dealer 1.5.0 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/coverage/index.html +876 -484
- data/hash_dealer.gemspec +1 -1
- data/lib/hash_dealer.rb +8 -3
- data/spec/lib/hash_dealer_spec.rb +13 -0
- metadata +1 -1
data/hash_dealer.gemspec
CHANGED
data/lib/hash_dealer.rb
CHANGED
@@ -69,14 +69,19 @@ class HashDealer
|
|
69
69
|
protected
|
70
70
|
|
71
71
|
# method missing
|
72
|
-
def method_missing(meth,
|
72
|
+
def method_missing(meth, *args, &block)
|
73
73
|
|
74
|
-
unless
|
74
|
+
unless args.length > 0 || block_given?
|
75
75
|
raise Exception.new(
|
76
76
|
"Please provide either a String or a block to #{meth}"
|
77
77
|
)
|
78
78
|
end
|
79
|
-
|
79
|
+
# a second arg is the options hash
|
80
|
+
opts = args[1] || {}
|
81
|
+
|
82
|
+
# the value is the first arg
|
83
|
+
value = args[0]
|
84
|
+
|
80
85
|
if opts[:optional]
|
81
86
|
@optional_attributes << meth.to_sym
|
82
87
|
end
|
@@ -220,6 +220,19 @@ describe HashDealer do
|
|
220
220
|
data[:child_value].should eql("x")
|
221
221
|
|
222
222
|
end
|
223
|
+
|
224
|
+
context "nil and false values" do
|
225
|
+
it "should allow nil and false values" do
|
226
|
+
HashDealer.define(:with_nil_and_false_values) do
|
227
|
+
nil_value nil
|
228
|
+
false_value false
|
229
|
+
end
|
230
|
+
HashDealer.roll(:with_nil_and_false_values).should eql({
|
231
|
+
:nil_value => nil,
|
232
|
+
:false_value => false
|
233
|
+
})
|
234
|
+
end
|
235
|
+
end
|
223
236
|
|
224
237
|
context "optional values" do
|
225
238
|
|