casted_hash 0.7.0 → 0.7.1
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.rb +10 -8
- data/test/test_casted_hash.rb +5 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a1417da9dece7f7c45f0ada321d3a8323cd9d870
|
|
4
|
+
data.tar.gz: 58bf74f4889f564454b40aa08cc1904d611b4478
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 78a0cd7f8705a8b389e1ebd5e051444e34c300fceba7bbfe4b751537f68547b27b6cbbdc06c17c0f28ce7480a681d2ea9c7e2e8cae8daa56ac5b221ce70f4b30
|
|
7
|
+
data.tar.gz: 05cd9e5be0896c45a755aecb64bdb5e70778e40fcda9b191dfc314bd756c4b40a519561cb21797e6c9c1e8046e0e1ffb4d00457c8f36e4b0051ecce62f045197
|
data/lib/casted_hash.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
class CastedHash < Hash
|
|
2
|
-
VERSION = "0.7.
|
|
2
|
+
VERSION = "0.7.1"
|
|
3
3
|
|
|
4
4
|
def initialize(constructor = {}, cast_proc = nil)
|
|
5
5
|
raise ArgumentError, "`cast_proc` required" unless cast_proc
|
|
@@ -148,31 +148,33 @@ protected
|
|
|
148
148
|
|
|
149
149
|
def uncast!(*keys)
|
|
150
150
|
@casted_keys.delete *keys.map(&:to_s)
|
|
151
|
-
@casting_keys.delete *keys.map(&:to_s)
|
|
152
151
|
end
|
|
153
152
|
|
|
154
153
|
def cast!(key)
|
|
154
|
+
key = convert_key(key)
|
|
155
155
|
return unless key?(key)
|
|
156
|
-
return regular_reader(
|
|
157
|
-
raise SystemStackError if casting?(key)
|
|
156
|
+
return regular_reader(key) if casted?(key)
|
|
157
|
+
raise SystemStackError, "already casting #{key}" if casting?(key)
|
|
158
158
|
|
|
159
159
|
casting! key
|
|
160
160
|
|
|
161
161
|
value = if @cast_proc.arity == 1
|
|
162
|
-
@cast_proc.call regular_reader(
|
|
162
|
+
@cast_proc.call regular_reader(key)
|
|
163
163
|
elsif @cast_proc.arity == 2
|
|
164
|
-
@cast_proc.call self, regular_reader(
|
|
164
|
+
@cast_proc.call self, regular_reader(key)
|
|
165
165
|
elsif @cast_proc.arity == 3
|
|
166
|
-
@cast_proc.call self, key, regular_reader(
|
|
166
|
+
@cast_proc.call self, key, regular_reader(key)
|
|
167
167
|
else
|
|
168
168
|
@cast_proc.call
|
|
169
169
|
end
|
|
170
170
|
|
|
171
|
-
value = regular_writer(
|
|
171
|
+
value = regular_writer(key, value)
|
|
172
172
|
|
|
173
173
|
casted! key
|
|
174
174
|
|
|
175
175
|
value
|
|
176
|
+
ensure
|
|
177
|
+
@casting_keys.delete convert_key(key)
|
|
176
178
|
end
|
|
177
179
|
|
|
178
180
|
def cast_all!
|
data/test/test_casted_hash.rb
CHANGED
|
@@ -17,9 +17,13 @@ describe CastedHash do
|
|
|
17
17
|
|
|
18
18
|
it "does not loop when refering to itself" do
|
|
19
19
|
@hash = CastedHash.new({:a => 1}, lambda {|x| @hash[:a] + 1 })
|
|
20
|
-
assert_raises(SystemStackError) do
|
|
20
|
+
error = assert_raises(SystemStackError) do
|
|
21
21
|
@hash[:a]
|
|
22
22
|
end
|
|
23
|
+
assert_equal "already casting a", error.message
|
|
24
|
+
assert_empty @hash.casted
|
|
25
|
+
assert !@hash.casted?(:a)
|
|
26
|
+
assert !@hash.casting?(:a)
|
|
23
27
|
end
|
|
24
28
|
|
|
25
29
|
it "can check size without casting" do
|