juvet 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/juvet/adapters/null_adapter.rb +4 -0
- data/lib/juvet/adapters/redis_adapter.rb +22 -4
- data/lib/juvet/bot.rb +4 -0
- data/lib/juvet/repository.rb +4 -0
- data/lib/juvet/version.rb +1 -1
- data/spec/juvet/adapters/null_adapter_spec.rb +6 -0
- data/spec/juvet/adapters/redis_adapter_spec.rb +14 -3
- data/spec/juvet/bot_spec.rb +7 -0
- data/spec/juvet/repository_spec.rb +7 -0
- 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: 5d0de0f49adf12f3bb1ee241861332316fb1beb2
|
4
|
+
data.tar.gz: 5bfb76bc640fd10ed6ff0d079e34f033879aee12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2a10cd29cdba17de6dd041a388abf3b21c349fd94987bfd96d33f77db9aba836daa5b0ecffed619a37958de921296bce8d0baf8bc68d5cdad7c914353f93840
|
7
|
+
data.tar.gz: c3702f246548de6bda6d1f6283f30ddc487b558f97fda747d6f3f18ea4b690e44c8ebb49f0985efb8c52d94455134f890614c84858136061ccac9a2c53885bfe
|
data/Gemfile.lock
CHANGED
@@ -11,6 +11,12 @@ module Juvet
|
|
11
11
|
@redis = Redis.new options
|
12
12
|
end
|
13
13
|
|
14
|
+
def all
|
15
|
+
redis.keys("#{collection_prefix}:*").map do |key|
|
16
|
+
find_by_key(key)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
14
20
|
def create(entity)
|
15
21
|
update_attributes entity
|
16
22
|
end
|
@@ -20,9 +26,7 @@ module Juvet
|
|
20
26
|
end
|
21
27
|
|
22
28
|
def find(id)
|
23
|
-
|
24
|
-
return nil if attributes.nil?
|
25
|
-
collection.entity.new ({ id: id }).merge(JSON.load(attributes))
|
29
|
+
find_by_key collection_key(id)
|
26
30
|
end
|
27
31
|
|
28
32
|
def persist(entity)
|
@@ -37,7 +41,21 @@ module Juvet
|
|
37
41
|
private
|
38
42
|
|
39
43
|
def collection_key(id)
|
40
|
-
"#{
|
44
|
+
"#{collection_prefix}:#{id}"
|
45
|
+
end
|
46
|
+
|
47
|
+
def collection_prefix
|
48
|
+
Juvet::String.new(collection.name).underscore
|
49
|
+
end
|
50
|
+
|
51
|
+
def find_by_key(key)
|
52
|
+
attributes = redis.get key
|
53
|
+
return nil if attributes.nil?
|
54
|
+
collection.entity.new ({ id: id_from_key(key) }).merge(JSON.load(attributes))
|
55
|
+
end
|
56
|
+
|
57
|
+
def id_from_key(key)
|
58
|
+
key.gsub("#{collection_prefix}:", "")
|
41
59
|
end
|
42
60
|
|
43
61
|
def key(entity)
|
data/lib/juvet/bot.rb
CHANGED
data/lib/juvet/repository.rb
CHANGED
data/lib/juvet/version.rb
CHANGED
@@ -2,6 +2,12 @@ describe Juvet::Adapters::NullAdapter do
|
|
2
2
|
let(:entity) { Object.new }
|
3
3
|
subject { described_class.new }
|
4
4
|
|
5
|
+
describe "#all" do
|
6
|
+
it "simply returns an empty array" do
|
7
|
+
expect(subject.all).to be_empty
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
5
11
|
describe "#create" do
|
6
12
|
it "simply returns the entity" do
|
7
13
|
expect(subject.create(entity)).to eq entity
|
@@ -14,13 +14,24 @@ describe Juvet::Adapters::RedisAdapter do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
let(:collection) { double(:collection, name: :entities, entity: Entity) }
|
17
|
-
let(:entity) { Entity.new id: 123 }
|
17
|
+
let(:entity) { Entity.new id: "123" }
|
18
18
|
let(:url) { "redis://localhost:6379" }
|
19
19
|
subject { described_class.new collection, url: url, db: 15 }
|
20
20
|
|
21
21
|
before(:all) { @redis = Redis.new db: 15 }
|
22
22
|
after(:all) { @redis.flushdb }
|
23
23
|
|
24
|
+
describe "#all" do
|
25
|
+
it "returns all the entities for a given collection" do
|
26
|
+
entity1 = subject.create(entity)
|
27
|
+
entity2 = subject.create(Entity.new(id: "1234"))
|
28
|
+
|
29
|
+
result = subject.all
|
30
|
+
|
31
|
+
expect(result.map(&:id)).to eq ["1234", "123"]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
24
35
|
describe "#create" do
|
25
36
|
it "stores the entity in the redis store" do
|
26
37
|
result = subject.create entity
|
@@ -48,7 +59,7 @@ describe Juvet::Adapters::RedisAdapter do
|
|
48
59
|
end
|
49
60
|
|
50
61
|
it "returns nil if the entity can't be found" do
|
51
|
-
result = subject.find 789
|
62
|
+
result = subject.find "789"
|
52
63
|
|
53
64
|
expect(result).to be_nil
|
54
65
|
end
|
@@ -84,7 +95,7 @@ describe Juvet::Adapters::RedisAdapter do
|
|
84
95
|
end
|
85
96
|
|
86
97
|
it "throws an exception if the entity is not already stored" do
|
87
|
-
entity = Entity.new id: 456
|
98
|
+
entity = Entity.new id: "456"
|
88
99
|
|
89
100
|
expect { subject.update entity }.to raise_error Juvet::EntityNotFoundError
|
90
101
|
end
|
data/spec/juvet/bot_spec.rb
CHANGED
@@ -25,6 +25,13 @@ describe Juvet::Bot do
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
+
describe ".all!" do
|
29
|
+
it "returns all the bots from the repository" do
|
30
|
+
expect(Juvet::BotRepository).to receive(:all)
|
31
|
+
described_class.all!
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
28
35
|
describe ".create!" do
|
29
36
|
it "stores the created instance in the repository" do
|
30
37
|
expect(Juvet::BotRepository).to receive(:create).with Juvet::Bot
|
@@ -7,6 +7,13 @@ describe Juvet::Repository do
|
|
7
7
|
expect(Repository.adapter).to be_instance_of Juvet::Adapters::NullAdapter
|
8
8
|
end
|
9
9
|
|
10
|
+
describe ".all" do
|
11
|
+
it "passes the retrieval to the adapter" do
|
12
|
+
expect(Repository.adapter).to receive(:all)
|
13
|
+
Repository.all
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
10
17
|
describe ".create" do
|
11
18
|
it "passes creation to the adapter" do
|
12
19
|
object = Object.new
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: juvet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jamie Wright
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|