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 +4 -4
- data/lib/casted_hash/value.rb +5 -0
- data/lib/casted_hash/version.rb +1 -1
- data/test/test_casted_hash.rb +8 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2f735188cdd5cdd37dc4227455a8ca9e47ba5c5c
|
|
4
|
+
data.tar.gz: c10f6c97be498703a37092e8972e09a982c1e789
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8785cacb5f811f22d70323ffab6d3bbb2b51a6ce1df80a99579df7101ca41bd0c456f68fe0d9511f6d986cea6852fc5bc7d0260df9bb6b6a2d291be949b52600
|
|
7
|
+
data.tar.gz: 2c4a168c1137d09894360cff7ac5d1ff757ba7edd251a46acade8f303ebb68abedea17d2dbc0990be46d6dd6e0d2e9bb945b1bd07d6ce71029c33688c72757f0
|
data/lib/casted_hash/value.rb
CHANGED
|
@@ -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
|
data/lib/casted_hash/version.rb
CHANGED
data/test/test_casted_hash.rb
CHANGED
|
@@ -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.
|
|
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-
|
|
11
|
+
date: 2013-11-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: equalizer
|