casted_hash 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/casted_hash.rb +11 -5
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 67cd2ef7fba5b62383915098fa8c7ed095daae42
4
- data.tar.gz: f556daabdb5492f66d54dd16ec1906902ff69538
3
+ metadata.gz: e8d0e1bf59f7f60cbc0ade6d0845c3e5dac3cad7
4
+ data.tar.gz: 44f2485a4e0c2a5a686ac72f025e638240be5e34
5
5
  SHA512:
6
- metadata.gz: 6d2d005f170d7448823d6f1e6e124ad8e1e3868319e1181e8c2e7428b7022fa84b0baf074654a1cae3d90f7d954424c4eb0e3b4b9137a32f000105dc2f5ea247
7
- data.tar.gz: 9d0f46b2265d9da6117055e8746406156e8ebfb53bb587ab6cc19fc5a56bf1ccf86047cf0ad7600789704a512ea8fca3a75aacdce3b3cb13ea65220956743d48
6
+ metadata.gz: b706bb8d8e5d4efbe59a633c075776938198bd0d00a50951500fda289d30f003b376e94ab5b12d364df7c199ded8fb0ce78180b37b92039bfe670aca8c45526f
7
+ data.tar.gz: 3d65221300c869f5670b4757bf1c9471056f8fec2607f0889978394eb5aef9e582c2a465085c65f1c680dd459e1fe6c803614fda43a6ea7c4fa3defce6dc31a8
data/lib/casted_hash.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  class CastedHash < Hash
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
 
4
4
  def initialize(constructor = {}, cast_proc = nil)
5
5
  raise ArgumentError, "`cast_proc` required" unless cast_proc
@@ -40,7 +40,7 @@ class CastedHash < Hash
40
40
  alias_method :regular_update, :update unless method_defined?(:regular_update)
41
41
 
42
42
  def []=(key, value)
43
- @casted_keys.delete key.to_s
43
+ uncast! key
44
44
  regular_writer(convert_key(key), value)
45
45
  end
46
46
 
@@ -54,7 +54,7 @@ class CastedHash < Hash
54
54
  return self if other_hash.empty?
55
55
 
56
56
  if other_hash.is_a? CastedHash
57
- other_hash.keys.each{|key| @casted_keys.delete key}
57
+ other_hash.keys.each{|key| uncast! key}
58
58
  super(other_hash)
59
59
  else
60
60
  other_hash.each_pair { |key, value| self[key] = value }
@@ -81,7 +81,7 @@ class CastedHash < Hash
81
81
  end
82
82
 
83
83
  def delete(key)
84
- @casted_keys.delete key.to_s
84
+ uncast! key
85
85
  super(convert_key(key))
86
86
  end
87
87
 
@@ -126,6 +126,10 @@ class CastedHash < Hash
126
126
 
127
127
  protected
128
128
 
129
+ def uncast!(*keys)
130
+ @casted_keys.delete *keys.map(&:to_s)
131
+ end
132
+
129
133
  def cast!(key)
130
134
  return unless key?(key)
131
135
  return regular_reader(convert_key(key)) if casted?(key)
@@ -134,7 +138,9 @@ protected
134
138
  value = if @cast_proc.arity == 1
135
139
  @cast_proc.call regular_reader(convert_key(key))
136
140
  elsif @cast_proc.arity == 2
137
- @cast_proc.call key, regular_reader(convert_key(key))
141
+ @cast_proc.call self, regular_reader(convert_key(key))
142
+ elsif @cast_proc.arity == 3
143
+ @cast_proc.call self, key, regular_reader(convert_key(key))
138
144
  else
139
145
  @cast_proc.call
140
146
  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.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephan Kaag