casted_hash 0.7.1 → 0.7.2

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: a1417da9dece7f7c45f0ada321d3a8323cd9d870
4
- data.tar.gz: 58bf74f4889f564454b40aa08cc1904d611b4478
3
+ metadata.gz: 70eb29b065f3d4a69aabf9338cb8805c1873444e
4
+ data.tar.gz: f01d58fd7cbba6eaad7ff0ed9c472091e13386e8
5
5
  SHA512:
6
- metadata.gz: 78a0cd7f8705a8b389e1ebd5e051444e34c300fceba7bbfe4b751537f68547b27b6cbbdc06c17c0f28ce7480a681d2ea9c7e2e8cae8daa56ac5b221ce70f4b30
7
- data.tar.gz: 05cd9e5be0896c45a755aecb64bdb5e70778e40fcda9b191dfc314bd756c4b40a519561cb21797e6c9c1e8046e0e1ffb4d00457c8f36e4b0051ecce62f045197
6
+ metadata.gz: e74b73ae86ecac1b17819be1ddb49976866bb8c01ccf1f3d9047516299e1b7124e4ee2d1bc4728f8b6507f791861badac84dd4edfea66ce3385368bba72cb380
7
+ data.tar.gz: 25b22c49c76ca944481fc27d90dae823a70e14f9d6ca9be606728b3b286c1ce6310b585df4dcc0cd9f0cfa56ff35d374cc03b2bad777b21898ed807c7b55c336
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
4
+ - 2.2.2
5
+ before_install: gem install bundler -v 1.10.3
6
+ services:
7
+ - redis-server
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [![Build Status](https://travis-ci.org/stephankaag/cached_hash.png?branch=master)](https://travis-ci.org/stephankaag/cached_hash)
1
+ [![Build Status](https://travis-ci.org/bettyblocks/casted_hash.svg)](https://travis-ci.org/bettyblocks/casted_hash)
2
2
 
3
3
  # CastedHash
4
4
 
data/lib/casted_hash.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  class CastedHash < Hash
2
- VERSION = "0.7.1"
2
+ VERSION = "0.7.2"
3
3
 
4
4
  def initialize(constructor = {}, cast_proc = nil)
5
5
  raise ArgumentError, "`cast_proc` required" unless cast_proc
@@ -150,22 +150,26 @@ protected
150
150
  @casted_keys.delete *keys.map(&:to_s)
151
151
  end
152
152
 
153
- def cast!(key)
153
+ def cast!(key, do_raise = true)
154
154
  key = convert_key(key)
155
155
  return unless key?(key)
156
- return regular_reader(key) if casted?(key)
157
- raise SystemStackError, "already casting #{key}" if casting?(key)
158
156
 
159
- casting! key
157
+ value = regular_reader(key)
158
+ return value if casted?(key)
160
159
 
161
- value = if @cast_proc.arity == 1
162
- @cast_proc.call regular_reader(key)
163
- elsif @cast_proc.arity == 2
164
- @cast_proc.call self, regular_reader(key)
165
- elsif @cast_proc.arity == 3
166
- @cast_proc.call self, key, regular_reader(key)
160
+ if casting?(key)
161
+ raise SystemStackError, "already casting #{key}" if do_raise
167
162
  else
168
- @cast_proc.call
163
+ casting! key
164
+ value = if @cast_proc.arity == 1
165
+ @cast_proc.call value
166
+ elsif @cast_proc.arity == 2
167
+ @cast_proc.call self, value
168
+ elsif @cast_proc.arity == 3
169
+ @cast_proc.call self, key, value
170
+ else
171
+ @cast_proc.call
172
+ end
169
173
  end
170
174
 
171
175
  value = regular_writer(key, value)
@@ -178,7 +182,7 @@ protected
178
182
  end
179
183
 
180
184
  def cast_all!
181
- keys.each{|key| cast! key}
185
+ keys.each{|key| cast!(key, false)}
182
186
  end
183
187
 
184
188
  def convert_key(key)
@@ -15,6 +15,11 @@ describe CastedHash do
15
15
  assert_equal "3", hash[:bar]
16
16
  end
17
17
 
18
+ it "can use casted_hash in cast method" do
19
+ @hash = CastedHash.new({:a => 1}, lambda {|x| @hash.casted_hash; 2 })
20
+ assert_equal 2, @hash[:a]
21
+ end
22
+
18
23
  it "does not loop when refering to itself" do
19
24
  @hash = CastedHash.new({:a => 1}, lambda {|x| @hash[:a] + 1 })
20
25
  error = assert_raises(SystemStackError) do
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.7.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephan Kaag
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-10 00:00:00.000000000 Z
11
+ date: 2016-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -74,6 +74,7 @@ extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
76
  - ".gitignore"
77
+ - ".travis.yml"
77
78
  - Gemfile
78
79
  - LICENSE.txt
79
80
  - README.md
@@ -101,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
102
  version: '0'
102
103
  requirements: []
103
104
  rubyforge_project:
104
- rubygems_version: 2.4.6
105
+ rubygems_version: 2.5.1
105
106
  signing_key:
106
107
  specification_version: 4
107
108
  summary: A casted hash