casted_hash 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b1524c82c2864754bdf75fd4845f8d2a1b4b829f
4
- data.tar.gz: 343ee8b30f139c23502e7476019058185aac4629
3
+ metadata.gz: 2f735188cdd5cdd37dc4227455a8ca9e47ba5c5c
4
+ data.tar.gz: c10f6c97be498703a37092e8972e09a982c1e789
5
5
  SHA512:
6
- metadata.gz: d5ba40da58b48bb4ce2b0b520720f914945686e1a8c91a9557f88d619fdd7a027509d36f6489e8c0790407ced3c1ad22fa0bedf471379c2aa061ec0411cb3ae3
7
- data.tar.gz: aba92b626a9386e2451205b0ec99311b434f8ab33041ae6127aab6bd1d76e569b91f4fffe91ca98df043b17b19e5951eec1d67c38fbd24fb714a002a459df63a
6
+ metadata.gz: 8785cacb5f811f22d70323ffab6d3bbb2b51a6ce1df80a99579df7101ca41bd0c456f68fe0d9511f6d986cea6852fc5bc7d0260df9bb6b6a2d291be949b52600
7
+ data.tar.gz: 2c4a168c1137d09894360cff7ac5d1ff757ba7edd251a46acade8f303ebb68abedea17d2dbc0990be46d6dd6e0d2e9bb945b1bd07d6ce71029c33688c72757f0
@@ -20,9 +20,14 @@ class CastedHash
20
20
 
21
21
  def cast!
22
22
  return if casted?
23
+ raise SystemStackError, "Cannot cast value that is currently being cast" if @casting
24
+
25
+ @casting = true
23
26
 
24
27
  @value = casted_hash.cast_proc.call(value)
28
+ ensure
25
29
  @casted = true
30
+ @casting = false
26
31
  end
27
32
  end
28
33
  end
@@ -1,3 +1,3 @@
1
1
  class CastedHash
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -16,6 +16,14 @@ class TestCastedHash < Minitest::Test
16
16
  assert_equal "3", hash[:bar]
17
17
  end
18
18
 
19
+ it "should not loop when refering to itself" do
20
+ @hash = CastedHash.new({:a => 1}, lambda {|x| @hash[:a] + 1 })
21
+ exception = assert_raises(SystemStackError) do
22
+ @hash[:a]
23
+ end
24
+ assert_equal "Cannot cast value that is currently being cast", exception.message
25
+ end
26
+
19
27
  it "should cast when expected" do
20
28
  hash = CastedHash.new({:a => 1, :b => 2}, lambda {|x| x + 10 })
21
29
  assert !hash.casted?(:a)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: casted_hash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephan Kaag
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-13 00:00:00.000000000 Z
11
+ date: 2013-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: equalizer