juvet 0.0.3 → 0.0.4
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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/juvet/attributable.rb +5 -5
- data/lib/juvet/bot.rb +1 -8
- data/lib/juvet/configuration/adapter.rb +6 -15
- data/lib/juvet/configuration/mapping.rb +4 -2
- data/lib/juvet/configuration.rb +4 -3
- data/lib/juvet/mapper/collection.rb +4 -2
- data/lib/juvet/mapper/mapped_repository.rb +12 -0
- data/lib/juvet/mapper.rb +7 -2
- data/lib/juvet/version.rb +1 -1
- data/spec/juvet/configuration/adapter_spec.rb +15 -12
- data/spec/juvet/configuration/mapping_spec.rb +2 -1
- data/spec/juvet/configuration_spec.rb +3 -7
- data/spec/juvet/mapper/collection_spec.rb +3 -2
- data/spec/juvet/mapper/mapped_repository_spec.rb +13 -0
- data/spec/juvet/mapper_spec.rb +14 -20
- data/spec/juvet_spec.rb +5 -3
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d3483a72f0e396a5f010a3ad73f5a1d888e89d2
|
4
|
+
data.tar.gz: 551045f13d3322dd05a2a1bd6574e9d32f37e07b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1dcd42919b068c0e841e1f7fa4052f6c5323f9d6071fb70b142dce80908f25835cd05661738cb9a2fdcd697c4ab4a09d0c8c1aee80f12f2c0cd657aa39c0e628
|
7
|
+
data.tar.gz: bd7ad250abe13a6c48caa4e0ec24d80090c669a5c86937f3faaaef49076c11ecadb398cb45eeda81a1927fffbf574e362421cbe11982e95576c501b81b655aa0
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
data/lib/juvet/attributable.rb
CHANGED
@@ -1,10 +1,5 @@
|
|
1
1
|
module Juvet
|
2
2
|
module Attributable
|
3
|
-
def initialize(attributes={})
|
4
|
-
initialize! attributes
|
5
|
-
attribute! attributes
|
6
|
-
end
|
7
|
-
|
8
3
|
def initialize!(attributes)
|
9
4
|
attributes.each { |name, value| set_variable! name, value }
|
10
5
|
end
|
@@ -26,6 +21,11 @@ module Juvet
|
|
26
21
|
|
27
22
|
private
|
28
23
|
|
24
|
+
def initialize(attributes={})
|
25
|
+
initialize! attributes
|
26
|
+
attribute! attributes
|
27
|
+
end
|
28
|
+
|
29
29
|
def create_method(name, &block)
|
30
30
|
self.class.send(:define_method, name, &block)
|
31
31
|
end
|
data/lib/juvet/bot.rb
CHANGED
@@ -6,7 +6,7 @@ module Juvet
|
|
6
6
|
|
7
7
|
class << self
|
8
8
|
def create(id, attributes={})
|
9
|
-
new id
|
9
|
+
new attributes.merge(id: id)
|
10
10
|
end
|
11
11
|
|
12
12
|
def create!(id, attributes={})
|
@@ -25,12 +25,5 @@ module Juvet
|
|
25
25
|
def update!(attributes={})
|
26
26
|
BotRepository.update self
|
27
27
|
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def initialize(id, attributes={})
|
32
|
-
@id = id
|
33
|
-
super attributes
|
34
|
-
end
|
35
28
|
end
|
36
29
|
end
|
@@ -5,35 +5,26 @@ module Juvet
|
|
5
5
|
attr_reader :options
|
6
6
|
attr_reader :type
|
7
7
|
|
8
|
-
def initialize(options={})
|
9
|
-
opts =
|
8
|
+
def initialize(type=nil, options={})
|
9
|
+
opts = (options || {}).dup
|
10
10
|
|
11
|
-
@type =
|
11
|
+
@type = type || :null
|
12
12
|
@options = opts
|
13
|
-
@class_name = Juvet::String.new("#{type}_adapter").classify
|
13
|
+
@class_name = Juvet::String.new("#{self.type}_adapter").classify
|
14
14
|
end
|
15
15
|
|
16
|
-
def build
|
16
|
+
def build
|
17
17
|
load_adapter
|
18
|
-
|
18
|
+
Juvet::Adapters.const_get(class_name)
|
19
19
|
end
|
20
20
|
|
21
21
|
private
|
22
22
|
|
23
|
-
def default_options
|
24
|
-
{ type: :null }.freeze
|
25
|
-
end
|
26
|
-
|
27
23
|
def load_adapter
|
28
24
|
require "juvet/adapters/#{type}_adapter"
|
29
25
|
rescue LoadError => e
|
30
26
|
raise LoadError.new("Cannot find Juvet adapter '#{type}' (#{e.message})")
|
31
27
|
end
|
32
|
-
|
33
|
-
def instantiate_adapter(mapper)
|
34
|
-
klass = Juvet::Adapters.const_get(class_name)
|
35
|
-
klass.new(mapper.collection_for_repository(klass), options)
|
36
|
-
end
|
37
28
|
end
|
38
29
|
end
|
39
30
|
end
|
data/lib/juvet/configuration.rb
CHANGED
@@ -3,8 +3,9 @@ require_relative "configuration/mapping"
|
|
3
3
|
|
4
4
|
module Juvet
|
5
5
|
class Configuration
|
6
|
-
def adapter(options=nil)
|
7
|
-
@adapter
|
6
|
+
def adapter(type=nil, options=nil)
|
7
|
+
return @adapter if type.nil?
|
8
|
+
@adapter ||= Juvet::Configuration::Adapter.new(type, options)
|
8
9
|
end
|
9
10
|
|
10
11
|
def mapping(&block)
|
@@ -12,7 +13,7 @@ module Juvet
|
|
12
13
|
end
|
13
14
|
|
14
15
|
def load!
|
15
|
-
|
16
|
+
mapping.build adapter
|
16
17
|
end
|
17
18
|
end
|
18
19
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require_relative "mapped_repository"
|
2
|
+
|
1
3
|
module Juvet
|
2
4
|
class Mapper
|
3
5
|
class Collection
|
@@ -16,9 +18,9 @@ module Juvet
|
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
19
|
-
def repository(klass=nil)
|
21
|
+
def repository(klass=nil, options=nil)
|
20
22
|
if klass
|
21
|
-
@repository = klass
|
23
|
+
@repository = MappedRepository.new klass, options
|
22
24
|
else
|
23
25
|
@repository
|
24
26
|
end
|
data/lib/juvet/mapper.rb
CHANGED
@@ -14,8 +14,13 @@ module Juvet
|
|
14
14
|
collections[name] = Juvet::Mapper::Collection.new name, &block
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
18
|
-
collections.
|
17
|
+
def build(adapter)
|
18
|
+
collections.each_pair do |name, collection|
|
19
|
+
if collection.repository && collection.repository.adapter == adapter.type
|
20
|
+
adapter_instance = adapter.build.new collection, adapter.options
|
21
|
+
collection.repository.klass.adapter = adapter_instance
|
22
|
+
end
|
23
|
+
end
|
19
24
|
end
|
20
25
|
end
|
21
26
|
end
|
data/lib/juvet/version.rb
CHANGED
@@ -1,26 +1,26 @@
|
|
1
1
|
describe Juvet::Configuration::Adapter do
|
2
2
|
describe "#type" do
|
3
3
|
it "sets the type from the options" do
|
4
|
-
subject = described_class.new
|
4
|
+
subject = described_class.new :null
|
5
5
|
expect(subject.type).to eq :null
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
9
|
describe "#options" do
|
10
10
|
it "includes any additional options initialized" do
|
11
|
-
subject = described_class.new
|
11
|
+
subject = described_class.new :null, blah: :bleh
|
12
12
|
expect(subject.options).to eq({ blah: :bleh })
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
describe "#class_name" do
|
17
17
|
it "creates a class name from the type" do
|
18
|
-
subject = described_class.new
|
18
|
+
subject = described_class.new :null
|
19
19
|
expect(subject.class_name).to eq "NullAdapter"
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
describe "default
|
23
|
+
describe "default type" do
|
24
24
|
it "has a null adapter type" do
|
25
25
|
expect(described_class.new.type).to eq :null
|
26
26
|
expect(described_class.new.class_name).to eq "NullAdapter"
|
@@ -28,19 +28,22 @@ describe Juvet::Configuration::Adapter do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
describe "#build" do
|
31
|
-
|
32
|
-
subject { described_class.new type: :null }
|
31
|
+
subject { described_class.new :redis }
|
33
32
|
|
34
|
-
it "
|
35
|
-
|
33
|
+
it "loads the adapter" do
|
34
|
+
subject.build
|
35
|
+
expect { Juvet::Adapters::RedisAdapter }.to_not raise_error
|
36
|
+
end
|
36
37
|
|
37
|
-
|
38
|
+
it "returns the class name for the adapter" do
|
39
|
+
klass = subject.build
|
40
|
+
expect(klass).to eq Juvet::Adapters::RedisAdapter
|
38
41
|
end
|
39
42
|
|
40
|
-
it "
|
41
|
-
subject = described_class.new
|
43
|
+
it "raises a load error if the adapter type cannot be loaded" do
|
44
|
+
subject = described_class.new :blah
|
42
45
|
|
43
|
-
expect { subject.build
|
46
|
+
expect { subject.build }.to raise_error LoadError
|
44
47
|
end
|
45
48
|
end
|
46
49
|
end
|
@@ -6,10 +6,11 @@ describe Juvet::Configuration::Mapping do
|
|
6
6
|
end
|
7
7
|
}
|
8
8
|
end
|
9
|
+
let(:adapter) { Juvet::Configuration::Adapter.new :null }
|
9
10
|
subject { described_class.new &blk }
|
10
11
|
|
11
12
|
it "creates a mapper from a block" do
|
12
|
-
result = subject.build
|
13
|
+
result = subject.build adapter
|
13
14
|
|
14
15
|
expect(result).to be_an_instance_of Juvet::Mapper
|
15
16
|
expect(result.collections.length).to eq 1
|
@@ -2,7 +2,7 @@ describe Juvet::Configuration do
|
|
2
2
|
subject { described_class.new }
|
3
3
|
|
4
4
|
it "has a default repository adapter" do
|
5
|
-
expect(subject.adapter).to be_instance_of Juvet::Configuration::Adapter
|
5
|
+
expect(subject.adapter(:null)).to be_instance_of Juvet::Configuration::Adapter
|
6
6
|
end
|
7
7
|
|
8
8
|
it "has a default mapping" do
|
@@ -13,12 +13,8 @@ describe Juvet::Configuration do
|
|
13
13
|
subject { described_class.new }
|
14
14
|
|
15
15
|
it "builds the mapping" do
|
16
|
-
|
17
|
-
subject.
|
18
|
-
end
|
19
|
-
|
20
|
-
it "builds the adapter" do
|
21
|
-
expect(subject.adapter).to receive(:build).with(Juvet::Mapper)
|
16
|
+
subject.adapter :null
|
17
|
+
expect(subject.mapping).to receive(:build).with(subject.adapter)
|
22
18
|
subject.load!
|
23
19
|
end
|
24
20
|
end
|
@@ -9,11 +9,12 @@ describe Juvet::Mapper::Collection do
|
|
9
9
|
it "executes the block if one is provided" do
|
10
10
|
subject = described_class.new(:widgets) do
|
11
11
|
entity Object
|
12
|
-
repository Object
|
12
|
+
repository Object, adapter: :blah
|
13
13
|
end
|
14
14
|
|
15
15
|
expect(subject.entity).to eq Object
|
16
|
-
expect(subject.repository).to eq Object
|
16
|
+
expect(subject.repository.klass).to eq Object
|
17
|
+
expect(subject.repository.adapter).to eq :blah
|
17
18
|
end
|
18
19
|
end
|
19
20
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
describe Juvet::Mapper::MappedRepository do
|
2
|
+
describe "#initialize" do
|
3
|
+
it "extracts the adapter from the options" do
|
4
|
+
subject = described_class.new Object, adapter: :blah
|
5
|
+
expect(subject.adapter).to eq :blah
|
6
|
+
end
|
7
|
+
|
8
|
+
it "defaults to the null adapter if it's not specified" do
|
9
|
+
subject = described_class.new Object
|
10
|
+
expect(subject.adapter).to eq :null
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/spec/juvet/mapper_spec.rb
CHANGED
@@ -10,19 +10,10 @@ describe Juvet::Mapper do
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
describe "#
|
14
|
-
|
15
|
-
|
16
|
-
it "adds a collection with the block" do
|
17
|
-
subject.collection(:widgets) do; end
|
18
|
-
|
19
|
-
expect(subject.collections[:widgets]).to \
|
20
|
-
be_instance_of Juvet::Mapper::Collection
|
13
|
+
describe "#build" do
|
14
|
+
class WidgetRepository
|
15
|
+
include Juvet::Repository
|
21
16
|
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "#collection_for_repository" do
|
25
|
-
class WidgetRepository; end
|
26
17
|
let(:subject) do
|
27
18
|
described_class.new do
|
28
19
|
collection :widgets do
|
@@ -31,17 +22,20 @@ describe Juvet::Mapper do
|
|
31
22
|
end
|
32
23
|
end
|
33
24
|
|
34
|
-
it "
|
35
|
-
|
36
|
-
|
37
|
-
expect(result.name).to eq :widgets
|
38
|
-
expect(result.repository).to eq WidgetRepository
|
25
|
+
it "sets the adapter on the repositories" do
|
26
|
+
expect(WidgetRepository).to receive(:adapter=).with(Juvet::Adapters::NullAdapter)
|
27
|
+
subject.build Juvet::Configuration::Adapter.new :null
|
39
28
|
end
|
29
|
+
end
|
40
30
|
|
41
|
-
|
42
|
-
|
31
|
+
describe "#collection" do
|
32
|
+
subject { described_class.new }
|
43
33
|
|
44
|
-
|
34
|
+
it "adds a collection with the block" do
|
35
|
+
subject.collection(:widgets) do; end
|
36
|
+
|
37
|
+
expect(subject.collections[:widgets]).to \
|
38
|
+
be_instance_of Juvet::Mapper::Collection
|
45
39
|
end
|
46
40
|
end
|
47
41
|
end
|
data/spec/juvet_spec.rb
CHANGED
@@ -19,9 +19,10 @@ describe Juvet do
|
|
19
19
|
|
20
20
|
it "sets up the adapter" do
|
21
21
|
described_class.configure do
|
22
|
-
adapter
|
22
|
+
adapter :null, blah: "blah"
|
23
23
|
end
|
24
|
-
expect(described_class.configuration.adapter).to
|
24
|
+
expect(described_class.configuration.adapter).to \
|
25
|
+
be_instance_of Juvet::Configuration::Adapter
|
25
26
|
expect(described_class.configuration.adapter.type).to eq :null
|
26
27
|
expect(described_class.configuration.adapter.options).to eq({ blah: "blah" })
|
27
28
|
expect(described_class.configuration.adapter.class_name).to eq "NullAdapter"
|
@@ -32,7 +33,8 @@ describe Juvet do
|
|
32
33
|
mapping do
|
33
34
|
end
|
34
35
|
end
|
35
|
-
expect(described_class.configuration.mapping).to
|
36
|
+
expect(described_class.configuration.mapping).to \
|
37
|
+
be_instance_of Juvet::Configuration::Mapping
|
36
38
|
end
|
37
39
|
end
|
38
40
|
end
|
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.4
|
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-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -52,6 +52,7 @@ files:
|
|
52
52
|
- lib/juvet/entity_not_found_error.rb
|
53
53
|
- lib/juvet/mapper.rb
|
54
54
|
- lib/juvet/mapper/collection.rb
|
55
|
+
- lib/juvet/mapper/mapped_repository.rb
|
55
56
|
- lib/juvet/repository.rb
|
56
57
|
- lib/juvet/string.rb
|
57
58
|
- lib/juvet/version.rb
|
@@ -63,6 +64,7 @@ files:
|
|
63
64
|
- spec/juvet/configuration/mapping_spec.rb
|
64
65
|
- spec/juvet/configuration_spec.rb
|
65
66
|
- spec/juvet/mapper/collection_spec.rb
|
67
|
+
- spec/juvet/mapper/mapped_repository_spec.rb
|
66
68
|
- spec/juvet/mapper_spec.rb
|
67
69
|
- spec/juvet/repository_spec.rb
|
68
70
|
- spec/juvet/string_spec.rb
|
@@ -101,6 +103,7 @@ test_files:
|
|
101
103
|
- spec/juvet/configuration/mapping_spec.rb
|
102
104
|
- spec/juvet/configuration_spec.rb
|
103
105
|
- spec/juvet/mapper/collection_spec.rb
|
106
|
+
- spec/juvet/mapper/mapped_repository_spec.rb
|
104
107
|
- spec/juvet/mapper_spec.rb
|
105
108
|
- spec/juvet/repository_spec.rb
|
106
109
|
- spec/juvet/string_spec.rb
|