casted_hash 0.4.0 → 0.5.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: 03429d3f8d64bf2d42f468c4ed15ebe30c68d974
4
- data.tar.gz: f5c433246cc97cbbf9d6d96ba033854fad44fd9a
3
+ metadata.gz: 67cd2ef7fba5b62383915098fa8c7ed095daae42
4
+ data.tar.gz: f556daabdb5492f66d54dd16ec1906902ff69538
5
5
  SHA512:
6
- metadata.gz: d5d42267a55f66917f881a02770fd4e08ab0de89074c09eb918ac3bc86e78bee55d368a70e4d65985ef8518e828144130db5b43082cd100cb857dcd69fb6d2c0
7
- data.tar.gz: 8f7671fd98530b3c5183ab6a1997d032cb99b9d538d83bef33ed6d0ca7ffb94e1edfd51a1593aa2fbfdcd4e9658d8e3c88a213a3e0b0bcc52ad333be52cd6a56
6
+ metadata.gz: 6d2d005f170d7448823d6f1e6e124ad8e1e3868319e1181e8c2e7428b7022fa84b0baf074654a1cae3d90f7d954424c4eb0e3b4b9137a32f000105dc2f5ea247
7
+ data.tar.gz: 9d0f46b2265d9da6117055e8746406156e8ebfb53bb587ab6cc19fc5a56bf1ccf86047cf0ad7600789704a512ea8fca3a75aacdce3b3cb13ea65220956743d48
data/lib/casted_hash.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  class CastedHash < Hash
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
 
4
4
  def initialize(constructor = {}, cast_proc = nil)
5
5
  raise ArgumentError, "`cast_proc` required" unless cast_proc
@@ -120,12 +120,16 @@ class CastedHash < Hash
120
120
  end
121
121
  end
122
122
 
123
+ def casted!(*keys)
124
+ @casted_keys.concat keys.map(&:to_s)
125
+ end
126
+
123
127
  protected
124
128
 
125
129
  def cast!(key)
126
130
  return unless key?(key)
127
131
  return regular_reader(convert_key(key)) if casted?(key)
128
- @casted_keys << key.to_s
132
+ casted! key
129
133
 
130
134
  value = if @cast_proc.arity == 1
131
135
  @cast_proc.call regular_reader(convert_key(key))
@@ -230,4 +230,12 @@ describe CastedHash do
230
230
  assert_equal 3, hash.fetch(:b)
231
231
  assert_equal({"a" => 2, "b" => 3}, hash.casted)
232
232
  end
233
+
234
+ it "allows bypassing of casting" do
235
+ hash = CastedHash.new({:a => 1, :b => 2, :c => 3}, lambda {|x|x + 1})
236
+ hash.casted! "a", :b
237
+ assert_equal 1, hash[:a]
238
+ assert_equal 2, hash[:b]
239
+ assert_equal 4, hash[:c]
240
+ end
233
241
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: casted_hash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephan Kaag