casted_hash 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3b382c55fba1c2a1e848ec4f8dc03534df1ec943
4
- data.tar.gz: 41ef0b6f8deaf0e2ecb43b8a2e7e665c76440e9f
3
+ metadata.gz: 03429d3f8d64bf2d42f468c4ed15ebe30c68d974
4
+ data.tar.gz: f5c433246cc97cbbf9d6d96ba033854fad44fd9a
5
5
  SHA512:
6
- metadata.gz: d0d9f2021e5cb127b01e1277b4331fa8da1f557ed10b07283f6c3a353014425c893c082bc47e1001caf1bc89a5df1f65ca1b5cc6c427dd880c25cda244f6b9fd
7
- data.tar.gz: 40949cd234aa281ae4f7577e0386e4b535e5c84bf91f28bbd71b797c82098e3e4a543b33f5a74bec15c4be8475093cf6a045969e81f7c11841679d95854a64cb
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.3.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)
@@ -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.3.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-24 00:00:00.000000000 Z
11
+ date: 2014-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler