hikki 0.0.2 → 0.0.3

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: b2946645f8620fbc6f5780dd8be60be4e4624cb1
4
- data.tar.gz: e30ff8be81ff55d2edbe949dd7c4fb1ede094630
3
+ metadata.gz: 3bffa4f8ad357c4095b1b2919fe7ee3e63ec4040
4
+ data.tar.gz: cc74e1cb2323c79bd3aac03190aadb5580cd72dd
5
5
  SHA512:
6
- metadata.gz: 56f839f488246485328d00ec650d30bb720c8c860d146df178c2223434fef9027be042ba96c2abc1e7a95e4c43e74cb5cd24e864751a97b18253d0539bf6e019
7
- data.tar.gz: 7189fff3b10d0819a6af42337ceb7c59787eb291037d8fdd38d5c5dd4a0e63d1726260579ba4fc3a61ed3ad53531962e413599dadea90ed12837b51ebca194e0
6
+ metadata.gz: 6afe248085889633e25f2ab5c08ba8f0b7255e8d8e7012a6d8e3aee32dae6ce9ee57f5df2c4c55bf77b784d8830800a5d9fab142ef2ff748a9401afffc01b189
7
+ data.tar.gz: 98aa16735f64e879a5abebf3c059d9d5354574e308dc0f27b3e2ed5f18112eba934488c0b1766dcd441090ec2c4d7c7256c60cedb17463b45a9e14e0a4c12e27
data/README.md CHANGED
@@ -61,7 +61,8 @@ repository.remove_all :people
61
61
  ```
62
62
 
63
63
  Hikki supports repositories with multiple adapters for reading and writing.
64
- It will write to all specified writers and read from the specified readers until a non-empty result is found.
64
+ It will write to all specified writers and read from the specified readers until a non-empty result is found. Since adapters each have their own `id` generation method, you should put the writer
65
+ in charge of generating the `id` first in the list.
65
66
 
66
67
  ```ruby
67
68
  redis = Hikki::Adapters::RedisAdapter.new
@@ -5,13 +5,14 @@ module Hikki
5
5
 
6
6
  def initialize(writers=[], readers=[])
7
7
  @writers = Array(writers)
8
- @writers << Hikki::Adapters::MemoryAdapter.new if @writers == []
8
+ @writers << Hikki::Adapters::MemoryAdapter.new if @writers.empty?
9
9
  @readers = Array(readers)
10
- @readers << @writers.first if @readers == []
10
+ @readers << @writers.first if @readers.empty?
11
11
  end
12
12
 
13
13
  def save(collection, data)
14
- writers.reduce({}) { |result, writer| writer.save(collection, data) }
14
+ head, *tail = *writers
15
+ tail.reduce(head.save(collection, data)) { |result, writer| writer.save(collection, result) }
15
16
  end
16
17
 
17
18
  def index(collection, field)
@@ -1,3 +1,3 @@
1
1
  module Hikki
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -5,11 +5,12 @@ module Hikki
5
5
  subject(:repository) { Repository.new(writers, readers) }
6
6
  let(:writers) { [writer] }
7
7
  let(:readers) { [reader] }
8
- let(:writer) { double :writer, save: data, index: true, remove: true, remove_all: true }
9
- let(:another_writer) { double :writer, save: data, index: true, remove: true, remove_all: true }
8
+ let(:writer) { double :writer, save: mod_data, index: true, remove: true, remove_all: true }
9
+ let(:another_writer) { double :writer, save: mod_data, index: true, remove: true, remove_all: true }
10
10
  let(:reader) { double :reader }
11
11
  let(:collection) { 'collection' }
12
- let(:data) { { id: '1' } }
12
+ let(:data) { { name: 'test' } }
13
+ let(:mod_data) { { 'id' => '1', 'name' => 'test' } }
13
14
 
14
15
  describe '.new' do
15
16
  context 'with no readers specified' do
@@ -40,16 +41,20 @@ module Hikki
40
41
  end
41
42
 
42
43
  it 'returns the data' do
43
- expect(repository.save(collection, data)).to eq data
44
+ expect(repository.save(collection, data)).to eq mod_data
44
45
  end
45
46
 
46
47
  context 'with a second writer' do
47
48
  before { repository.writers << another_writer }
48
49
 
49
50
  it 'calls save on both of the writers' do
51
+ expect(writer).to receive(:save).with(collection, data).and_return(mod_data)
50
52
  repository.save(collection, data)
51
- expect(writer).to have_received(:save).with(collection, data)
52
- expect(another_writer).to have_received(:save).with(collection, data)
53
+ expect(another_writer).to have_received(:save).with(collection, mod_data)
54
+ end
55
+
56
+ it 'returns the data' do
57
+ expect(repository.save(collection, data)).to eq mod_data
53
58
  end
54
59
  end
55
60
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hikki
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - alexpeachey
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-25 00:00:00.000000000 Z
11
+ date: 2014-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler