perforated 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 64e25f900f7679d5f4f579b0241ae489e282067f
4
- data.tar.gz: 89faaf88ca21ab566ae430bcf191340e979657fd
3
+ metadata.gz: 2188079862ccf0f34ad99dc8ef2575101f54f6a4
4
+ data.tar.gz: 1083c36661390745858282f788f483ac434fb7c2
5
5
  SHA512:
6
- metadata.gz: 71f125afe780caffb948823f4df8650e03f9909ae20e4fa9bc4d00aae486f9fa2826389150ec75c086091da6adfc084f50f974d9c455f95b333f2c82610424b0
7
- data.tar.gz: dcaad74a443699fbaf91c35cee0df77c96b75ffa98c63600f0db07313072e3b181165311d78745a5db681469def7f24a18cbd22fe40b27b1a178f6d3a0971857
6
+ metadata.gz: 850b58a8bea4aed87934f41e03f47fb3a459eeaa1dd513dad53eaf5e41efc7e268cfbf5ee7688e01eaf6573ca0c98477ea1683c11aa4e956eaabdcbec160f4b6
7
+ data.tar.gz: 55afde3e6a522aac92ce38cf4891b774065c7d69c59da9a3ff59f7fa5eb8d7cdc5854aa32c0b5e65b91abb4d2a3508db8ab2191250e644a1156d9d8e4db628a8
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## Version 0.7.0
2
+
3
+ * Alter the implementation of `fetch_multi` to return a hash rather than an
4
+ array. This is consistent with the new Dalli implementation, and what should
5
+ be new the Rails implementation.
6
+
1
7
  ## Version 0.6.0
2
8
 
3
9
  * Prevent frozen string errors by duplicating hash keys before fetching.
@@ -11,20 +11,15 @@ module Perforated
11
11
  keyed = keyed_enumerable('as-json')
12
12
  keys = keyed.keys.map(&:dup)
13
13
 
14
- Perforated::Compatibility.fetch_multi(*keys) do |key|
15
- keyed[key].as_json
16
- end
14
+ fetch_multi(keys) { |key| keyed[key].as_json }.values
17
15
  end
18
16
 
19
17
  def to_json(*)
20
- keyed = keyed_enumerable('to-json')
21
- keys = keyed.keys.map(&:dup)
22
-
23
- json_objects = Perforated::Compatibility.fetch_multi(*keys) do |key|
24
- keyed[key].to_json
25
- end
18
+ keyed = keyed_enumerable('to-json')
19
+ keys = keyed.keys.map(&:dup)
20
+ objects = fetch_multi(keys) { |key| keyed[key].to_json }
26
21
 
27
- "[#{json_objects.join(',')}]"
22
+ "[#{objects.values.join(',')}]"
28
23
  end
29
24
 
30
25
  private
@@ -35,5 +30,9 @@ module Perforated
35
30
  memo
36
31
  end
37
32
  end
33
+
34
+ def fetch_multi(keys, &block)
35
+ Perforated::Compatibility.fetch_multi *keys, &block
36
+ end
38
37
  end
39
38
  end
@@ -13,12 +13,14 @@ module Perforated
13
13
  options = {}
14
14
  results = Perforated.cache.read_multi(*names, options)
15
15
 
16
- names.map do |name|
17
- results.fetch(name) do
16
+ names.inject({}) do |memo, (name, _)|
17
+ memo[name] = results.fetch(name) do
18
18
  value = yield name
19
19
  Perforated.cache.write(name, value, options)
20
20
  value
21
21
  end
22
+
23
+ memo
22
24
  end
23
25
  end
24
26
  end
@@ -1,3 +1,3 @@
1
1
  module Perforated
2
- VERSION = '0.6.0'
2
+ VERSION = '0.7.0'
3
3
  end
@@ -24,10 +24,10 @@ describe Perforated::Cache do
24
24
  array = [ruby, elixir]
25
25
  cache = Perforated::Cache.new(array)
26
26
 
27
- cache.as_json.should == [{ name: 'Ruby' }, { name: 'Elixir' }]
27
+ expect(cache.as_json).to eq([{ name: 'Ruby' }, { name: 'Elixir' }])
28
28
 
29
- Perforated.cache.read('Language/Ruby/as-json').should == ruby.as_json
30
- Perforated.cache.read('Language/Elixir/as-json').should == elixir.as_json
29
+ expect(Perforated.cache.read('Language/Ruby/as-json')).to eq(ruby.as_json)
30
+ expect(Perforated.cache.read('Language/Elixir/as-json')).to eq(elixir.as_json)
31
31
  end
32
32
 
33
33
  it 'does not overwrite existing key values' do
@@ -36,7 +36,7 @@ describe Perforated::Cache do
36
36
 
37
37
  Perforated::Cache.new([erlang]).as_json
38
38
 
39
- Perforated.cache.read('Language/Erlang/as-json').should == { name: 'Elixir' }
39
+ expect(Perforated.cache.read('Language/Erlang/as-json')).to eq(name: 'Elixir')
40
40
  end
41
41
  end
42
42
 
@@ -44,10 +44,9 @@ describe Perforated::Cache do
44
44
  it 'constructs a stringified json array of underlying values' do
45
45
  cache = Perforated::Cache.new([Language.new('Ruby'), Language.new('Elixir')])
46
46
 
47
- cache.to_json.should == %([{"name":"Ruby"},{"name":"Elixir"}])
48
-
49
- Perforated.cache.exist?('Language/Ruby/to-json').should be_true
50
- Perforated.cache.exist?('Language/Elixir/to-json').should be_true
47
+ expect(cache.to_json).to eq(%([{"name":"Ruby"},{"name":"Elixir"}]))
48
+ expect(Perforated.cache.exist?('Language/Ruby/to-json')).to be_true
49
+ expect(Perforated.cache.exist?('Language/Elixir/to-json')).to be_true
51
50
  end
52
51
  end
53
52
  end
@@ -13,11 +13,9 @@ describe Perforated::Compatibility do
13
13
  end
14
14
 
15
15
  it 'falls back to the custom backfill if the cache does not support it' do
16
- cache = Perforated.cache
16
+ results = Perforated::Compatibility.fetch_multi(:one, :two) { |key| key.to_s }
17
17
 
18
- Perforated::Compatibility.fetch_multi(:one, :two) do |key|
19
- key
20
- end
18
+ expect(results).to eq(one: 'one', two: 'two')
21
19
  end
22
20
  end
23
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: perforated
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Parker Selbert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-13 00:00:00.000000000 Z
11
+ date: 2013-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport