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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 435c9ec1908e446eadcabfbd799e211f4b794831
4
- data.tar.gz: 6468a6f6506e6a9788a62e589e2f6c636ab3e603
3
+ metadata.gz: 070a314766d03d1326f0ad6306df78ff51f4dc24
4
+ data.tar.gz: fb711994359bbc24bbe18b8f58179ea7e214f121
5
5
  SHA512:
6
- metadata.gz: 887e1b2094f5b91242fe2a2c17b63de4160db7ec3b76d57c4b66b818e02a2aea356c10cbf674410d0314fef95f9cac9ecb5248c3deb0833bb1ea495281025890
7
- data.tar.gz: dcb3e970ee5abd68ade49a25a7b2b13c55bfaea88bebb5482c07191fa2894f317675ccee7a50fb791107adb236455d1b062affccec136202a0ef5e7ef5bf4bc0
6
+ metadata.gz: 4f8ec2f9ebccaeb047f2ff69bb582ba3ab53a3ad15201e3326f083e3e6ef5804ee6f42dd262fa9b3b4fe9ea722649818d9f83a4edfd1bb333489d6b95eac612a
7
+ data.tar.gz: 01e2cf1c0cc210269f1ba2e7352afcc46f405340e6f951aff126070b775a87d3f4fbcf6a553eee1192ca5356f7b338c4b7218cda4a9fc1a8769f93c4f7cb8b95
@@ -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|variables.key?(key.to_s) || variables.key?(key.to_sym)}
29
- previous_inverse_hash = @inverse_hash.select{|key|variables.key?(key.to_s) || variables.key?(key.to_sym)}
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
@@ -1,3 +1,3 @@
1
1
  class Scash
2
- VERSION = "0.3.3"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -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.3.3
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: 2015-03-03 00:00:00.000000000 Z
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.2.2
119
+ rubygems_version: 2.4.5.1
120
120
  signing_key:
121
121
  specification_version: 4
122
122
  summary: A scoped hash