hash-proxy 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,6 @@
1
+ # == Version 0.1.3 / 2012-08-13
2
+ # * Support to_ary method on NullObject
3
+ #
1
4
  # == Version 0.1.2 / 2012-06-15
2
5
  # * Fix bug for hashes with false as a value
3
6
  #
data/README.md CHANGED
@@ -39,6 +39,17 @@ Also supports hash like semantics:
39
39
  puts "#{k}: #{v}"
40
40
  end
41
41
 
42
+ Limitations
43
+ -----------
44
+
45
+ Because it mixes in Enumerable, the Proxy class doesn't play nice with keys whose names correspond to
46
+ methods on Enumerable. The work around: for keys that are methods on Enumerable, use the hash accessor
47
+ instead of the method call notation:
48
+
49
+ proxy = HashProxy.create_from(:size => 42)
50
+ proxy.size => 1 (the number of key-value pairs in the proxied Hash)
51
+ proxy[:size] => 42 (the value pointed to by the :size key)
52
+
42
53
  Requirements
43
54
  ------------
44
55
 
@@ -70,6 +81,9 @@ Original author: Douglas A. Seifert (doug@dseifert.net)
70
81
  History
71
82
  -------
72
83
 
84
+ ### Version 0.1.3 / 2012-08-13
85
+ * Support to_ary method on NullObject
86
+
73
87
  ### Version 0.1.2 / 2012-06-15
74
88
  * Fix bug with hashes with false as a value
75
89
 
@@ -7,6 +7,9 @@ module HashProxy
7
7
  # Returns an empty array
8
8
  def to_a; []; end
9
9
 
10
+ # Returns an empty array
11
+ def to_ary; []; end
12
+
10
13
  # Returns an empty string
11
14
  def to_s; ""; end
12
15
 
@@ -2,17 +2,32 @@
2
2
  require File.expand_path('../spec_helper', __FILE__)
3
3
 
4
4
  describe HashProxy do
5
+ it "works with null values" do
6
+ proxy = HashProxy.create_from(:null => nil)
7
+ proxy.size.should eq(1)
8
+ proxy.null.should be_nil
9
+ proxy.null.class.should eq(HashProxy::NullObject)
10
+ proxy.null.to_a.should eq([])
11
+ proxy.null.to_ary.should eq([])
12
+ end
13
+
14
+ it "works with keys called size" do
15
+ proxy = HashProxy.create_from(:size => 42, :bar => :foo)
16
+ proxy.size.should eq(2)
17
+ proxy[:size].should == 42
18
+ end
19
+
5
20
 
6
21
  it "handles booleans" do
7
22
  proxy = HashProxy.create_from(:indexed => false, :followed => true)
8
- proxy[:indexed].should == false
9
- proxy[:followed].should == true
23
+ proxy.indexed.should eq(false)
24
+ proxy.followed.should == true
10
25
  end
11
26
 
12
27
  it "does not get confused by methods defined on Kernel" do
13
28
  proxy = HashProxy::Proxy.new({})
14
29
  lambda { proxy[:format] }.should_not raise_error
15
- proxy[:format].should be_nil
30
+ proxy.format.should be_nil
16
31
  end
17
32
 
18
33
  it "supports enumerable" do
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hash-proxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-15 00:00:00.000000000 Z
12
+ date: 2012-08-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bones