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 +4 -4
- data/README.md +2 -1
- data/lib/hikki/repository.rb +4 -3
- data/lib/hikki/version.rb +1 -1
- data/spec/hikki/repository_spec.rb +11 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3bffa4f8ad357c4095b1b2919fe7ee3e63ec4040
|
4
|
+
data.tar.gz: cc74e1cb2323c79bd3aac03190aadb5580cd72dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/hikki/repository.rb
CHANGED
@@ -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
|
-
|
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)
|
data/lib/hikki/version.rb
CHANGED
@@ -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:
|
9
|
-
let(:another_writer) { double :writer, save:
|
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) { {
|
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
|
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(
|
52
|
-
|
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.
|
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-
|
11
|
+
date: 2014-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|