casted_hash 0.3.0 → 0.4.0
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 +9 -1
- data/test/test_casted_hash.rb +10 -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: 03429d3f8d64bf2d42f468c4ed15ebe30c68d974
|
|
4
|
+
data.tar.gz: f5c433246cc97cbbf9d6d96ba033854fad44fd9a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d5d42267a55f66917f881a02770fd4e08ab0de89074c09eb918ac3bc86e78bee55d368a70e4d65985ef8518e828144130db5b43082cd100cb857dcd69fb6d2c0
|
|
7
|
+
data.tar.gz: 8f7671fd98530b3c5183ab6a1997d032cb99b9d538d83bef33ed6d0ca7ffb94e1edfd51a1593aa2fbfdcd4e9658d8e3c88a213a3e0b0bcc52ad333be52cd6a56
|
data/lib/casted_hash.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
class CastedHash < Hash
|
|
2
|
-
VERSION = "0.
|
|
2
|
+
VERSION = "0.4.0"
|
|
3
3
|
|
|
4
4
|
def initialize(constructor = {}, cast_proc = nil)
|
|
5
5
|
raise ArgumentError, "`cast_proc` required" unless cast_proc
|
|
@@ -112,6 +112,14 @@ class CastedHash < Hash
|
|
|
112
112
|
end
|
|
113
113
|
end
|
|
114
114
|
|
|
115
|
+
def casted
|
|
116
|
+
Hash.new.tap do |hash|
|
|
117
|
+
@casted_keys.each do |key|
|
|
118
|
+
hash[key] = regular_reader(key)
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
115
123
|
protected
|
|
116
124
|
|
|
117
125
|
def cast!(key)
|
data/test/test_casted_hash.rb
CHANGED
|
@@ -220,4 +220,14 @@ describe CastedHash do
|
|
|
220
220
|
assert_equal 3, hash.fetch(:b)
|
|
221
221
|
assert_equal({"a" => 2, "b" => 3}, hash.to_hash)
|
|
222
222
|
end
|
|
223
|
+
|
|
224
|
+
it "allows access to casted keys only" do
|
|
225
|
+
hash = CastedHash.new({:a => 1, :b => 2}, lambda {|x|x + 1})
|
|
226
|
+
assert_equal Hash, hash.casted.class
|
|
227
|
+
assert_equal({}, hash.casted)
|
|
228
|
+
assert_equal 2, hash.fetch(:a)
|
|
229
|
+
assert_equal({"a" => 2}, hash.casted)
|
|
230
|
+
assert_equal 3, hash.fetch(:b)
|
|
231
|
+
assert_equal({"a" => 2, "b" => 3}, hash.casted)
|
|
232
|
+
end
|
|
223
233
|
end
|
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.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Stephan Kaag
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-09-
|
|
11
|
+
date: 2014-09-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|