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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2766e44c7cab47d5330284c6277d51f28ede5436
4
- data.tar.gz: 44787b63218ed0b0da0dea2f20bffd97c94e8649
3
+ metadata.gz: 3b382c55fba1c2a1e848ec4f8dc03534df1ec943
4
+ data.tar.gz: 41ef0b6f8deaf0e2ecb43b8a2e7e665c76440e9f
5
5
  SHA512:
6
- metadata.gz: 7d1b9bb7ff8d5bf2e730fb825bacd7643f98b262731a20838a466539842c681d32fa97dc1e06c5d3a5096888a81521bd43931173f678d0d5671cb13e6d48c4fc
7
- data.tar.gz: 5ac7495d36dcb79f6f6314190de38332075f1a8f87a7c21967cb6cb3a0a8fc6b7211248b582cff1a7c5dcc5ef4a08cca954c501260d40b254330576b39781aee
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.1"
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
@@ -211,4 +211,13 @@ describe CastedHash do
211
211
  assert_equal ["a", "b"], hash.keys
212
212
  end
213
213
 
214
- end
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.2.1
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-01-27 00:00:00.000000000 Z
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.0
104
+ rubygems_version: 2.2.2
105
105
  signing_key:
106
106
  specification_version: 4
107
107
  summary: A casted hash