casted_hash 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/casted_hash.rb +10 -2
- data/test/test_casted_hash.rb +10 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b382c55fba1c2a1e848ec4f8dc03534df1ec943
|
4
|
+
data.tar.gz: 41ef0b6f8deaf0e2ecb43b8a2e7e665c76440e9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0d9f2021e5cb127b01e1277b4331fa8da1f557ed10b07283f6c3a353014425c893c082bc47e1001caf1bc89a5df1f65ca1b5cc6c427dd880c25cda244f6b9fd
|
7
|
+
data.tar.gz: 40949cd234aa281ae4f7577e0386e4b535e5c84bf91f28bbd71b797c82098e3e4a543b33f5a74bec15c4be8475093cf6a045969e81f7c11841679d95854a64cb
|
data/lib/casted_hash.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class CastedHash < Hash
|
2
|
-
VERSION = "0.
|
2
|
+
VERSION = "0.3.0"
|
3
3
|
|
4
4
|
def initialize(constructor = {}, cast_proc = nil)
|
5
5
|
raise ArgumentError, "`cast_proc` required" unless cast_proc
|
@@ -104,6 +104,14 @@ class CastedHash < Hash
|
|
104
104
|
@casted_keys.include?(key.to_s)
|
105
105
|
end
|
106
106
|
|
107
|
+
def to_hash
|
108
|
+
Hash.new.tap do |hash|
|
109
|
+
keys.each do |key|
|
110
|
+
hash[key] = regular_reader(key)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
107
115
|
protected
|
108
116
|
|
109
117
|
def cast!(key)
|
@@ -130,4 +138,4 @@ protected
|
|
130
138
|
key.kind_of?(Symbol) ? key.to_s : key
|
131
139
|
end
|
132
140
|
|
133
|
-
end
|
141
|
+
end
|
data/test/test_casted_hash.rb
CHANGED
@@ -211,4 +211,13 @@ describe CastedHash do
|
|
211
211
|
assert_equal ["a", "b"], hash.keys
|
212
212
|
end
|
213
213
|
|
214
|
-
|
214
|
+
it "allows access to 'raw' hash" do
|
215
|
+
hash = CastedHash.new({:a => 1, :b => 2}, lambda {|x|x + 1})
|
216
|
+
assert_equal Hash, hash.to_hash.class
|
217
|
+
assert_equal({"a" => 1, "b" => 2}, hash.to_hash)
|
218
|
+
assert_equal 2, hash.fetch(:a)
|
219
|
+
assert_equal({"a" => 2, "b" => 2}, hash.to_hash)
|
220
|
+
assert_equal 3, hash.fetch(:b)
|
221
|
+
assert_equal({"a" => 2, "b" => 3}, hash.to_hash)
|
222
|
+
end
|
223
|
+
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.3.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-
|
11
|
+
date: 2014-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -101,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
101
|
version: '0'
|
102
102
|
requirements: []
|
103
103
|
rubyforge_project:
|
104
|
-
rubygems_version: 2.2.
|
104
|
+
rubygems_version: 2.2.2
|
105
105
|
signing_key:
|
106
106
|
specification_version: 4
|
107
107
|
summary: A casted hash
|