scash 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/scash.rb +3 -2
- data/lib/scash/version.rb +1 -1
- data/test/test_scash.rb +29 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 070a314766d03d1326f0ad6306df78ff51f4dc24
|
4
|
+
data.tar.gz: fb711994359bbc24bbe18b8f58179ea7e214f121
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f8ec2f9ebccaeb047f2ff69bb582ba3ab53a3ad15201e3326f083e3e6ef5804ee6f42dd262fa9b3b4fe9ea722649818d9f83a4edfd1bb333489d6b95eac612a
|
7
|
+
data.tar.gz: 01e2cf1c0cc210269f1ba2e7352afcc46f405340e6f951aff126070b775a87d3f4fbcf6a553eee1192ca5356f7b338c4b7218cda4a9fc1a8769f93c4f7cb8b95
|
data/lib/scash.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "active_support/hash_with_indifferent_access"
|
2
2
|
require "active_support/core_ext/hash/indifferent_access"
|
3
|
+
require "active_support/core_ext/hash/slice"
|
3
4
|
require "active_support/core_ext/module/delegation"
|
4
5
|
require "scash/version"
|
5
6
|
|
@@ -25,8 +26,8 @@ class Scash
|
|
25
26
|
end
|
26
27
|
|
27
28
|
def scope(variables)
|
28
|
-
previous_hash = @hash.select{|key|
|
29
|
-
previous_inverse_hash = @inverse_hash.select{|key|
|
29
|
+
previous_hash = @hash.slice *variables.keys.select{|key| @hash.key?(key)}
|
30
|
+
previous_inverse_hash = @inverse_hash.slice *variables.keys.select{|key| @inverse_hash.key?(key)}
|
30
31
|
@hash.merge! variables
|
31
32
|
@inverse_hash.merge!(variables.reject{|key| @inverse_hash.key?(key)})
|
32
33
|
yield
|
data/lib/scash/version.rb
CHANGED
data/test/test_scash.rb
CHANGED
@@ -206,4 +206,33 @@ describe Scash do
|
|
206
206
|
assert_equal({:a => 1, :b => 2}.with_indifferent_access, scash.merge(:b => 2))
|
207
207
|
end
|
208
208
|
end
|
209
|
+
|
210
|
+
it "respects key conversion" do
|
211
|
+
ihash = HashWithIndifferentAccess.new(:a => 1)
|
212
|
+
def ihash.convert_key(key)
|
213
|
+
key.to_s.gsub(/^secret_/, "")
|
214
|
+
end
|
215
|
+
|
216
|
+
scash = Scash.new ihash
|
217
|
+
def scash.[](key)
|
218
|
+
@hash.fetch(key)
|
219
|
+
end
|
220
|
+
|
221
|
+
assert_equal 1, scash["a"]
|
222
|
+
assert_equal 1, scash[:a]
|
223
|
+
assert_equal 1, scash["secret_a"]
|
224
|
+
assert_equal 1, scash[:secret_a]
|
225
|
+
|
226
|
+
scash.with({:secret_a => 2}) do
|
227
|
+
assert_equal 2, scash["a"]
|
228
|
+
assert_equal 2, scash[:a]
|
229
|
+
assert_equal 2, scash["secret_a"]
|
230
|
+
assert_equal 2, scash[:secret_a]
|
231
|
+
end
|
232
|
+
|
233
|
+
assert_equal 1, scash["a"]
|
234
|
+
assert_equal 1, scash[:a]
|
235
|
+
assert_equal 1, scash["secret_a"]
|
236
|
+
assert_equal 1, scash[:secret_a]
|
237
|
+
end
|
209
238
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 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:
|
11
|
+
date: 2016-04-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -116,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
116
|
version: '0'
|
117
117
|
requirements: []
|
118
118
|
rubyforge_project:
|
119
|
-
rubygems_version: 2.
|
119
|
+
rubygems_version: 2.4.5.1
|
120
120
|
signing_key:
|
121
121
|
specification_version: 4
|
122
122
|
summary: A scoped hash
|