gummi 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/gummi/repository_layer/repository.rb +22 -26
- data/lib/gummi/version.rb +1 -1
- data/lib/gummi.rb +0 -1
- data/lib/repobahn/repository.rb +19 -13
- data/spec/lib/gummi/repository_layer/repository_spec.rb +13 -9
- data/spec/lib/repobahn/repository_spec.rb +3 -2
- data/spec/support/models/people.rb +1 -1
- metadata +8 -3
- data/lib/repobahn/repository/active_record.rb +0 -17
@@ -8,36 +8,32 @@ module Gummi
|
|
8
8
|
after_conversion :set_id_and_version
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
db_instance_to_entity document if document
|
16
|
-
end
|
17
|
-
|
18
|
-
def search(options = {}, &block)
|
19
|
-
search = db_class.new_filtered_search(options)
|
20
|
-
yield search if block_given?
|
21
|
-
Repository::Result.new search.execute, self
|
22
|
-
end
|
11
|
+
def get(id)
|
12
|
+
document = db_class.get id
|
13
|
+
db_instance_to_entity document if document
|
14
|
+
end
|
23
15
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
16
|
+
def search(options = {}, &block)
|
17
|
+
search = db_class.new_filtered_search(options)
|
18
|
+
yield search if block_given?
|
19
|
+
Repository::Result.new search.execute, self
|
20
|
+
end
|
29
21
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
22
|
+
def raw_search(options = {}, &block)
|
23
|
+
search = db_class.new_raw_search(options)
|
24
|
+
yield search if block_given?
|
25
|
+
Repository::Result.new search.execute, self
|
26
|
+
end
|
35
27
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
28
|
+
def overwrite(entity)
|
29
|
+
return false unless entity.valid?
|
30
|
+
document = db_class.new(entity.attributes)
|
31
|
+
document.overwrite
|
32
|
+
end
|
40
33
|
|
34
|
+
def set_id_and_version(entity, db_instance)
|
35
|
+
entity.id = db_instance.id
|
36
|
+
entity.version = db_instance.version
|
41
37
|
end
|
42
38
|
|
43
39
|
end
|
data/lib/gummi/version.rb
CHANGED
data/lib/gummi.rb
CHANGED
data/lib/repobahn/repository.rb
CHANGED
@@ -2,8 +2,6 @@ module Repobahn
|
|
2
2
|
module Repository
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
|
-
include ::Repobahn::Repository::ActiveRecord
|
6
|
-
|
7
5
|
included do
|
8
6
|
include Hooks
|
9
7
|
define_hook :after_conversion
|
@@ -21,17 +19,6 @@ module Repobahn
|
|
21
19
|
@entity_class || default_entity_class
|
22
20
|
end
|
23
21
|
|
24
|
-
def db_instances_to_entities(db_instances)
|
25
|
-
entities = Array(db_instances).map { |db_instance| db_instance_to_entity(db_instance) }
|
26
|
-
entities.length > 1 ? entities : entities.first
|
27
|
-
end
|
28
|
-
|
29
|
-
def db_instance_to_entity(db_instance)
|
30
|
-
entity = entity_class.new(db_instance.attributes)
|
31
|
-
run_hook :after_conversion, entity, db_instance
|
32
|
-
entity
|
33
|
-
end
|
34
|
-
|
35
22
|
private
|
36
23
|
|
37
24
|
def default_db_class
|
@@ -45,5 +32,24 @@ module Repobahn
|
|
45
32
|
end
|
46
33
|
|
47
34
|
end
|
35
|
+
|
36
|
+
def db_class
|
37
|
+
self.class.db_class
|
38
|
+
end
|
39
|
+
|
40
|
+
def entity_class
|
41
|
+
self.class.entity_class
|
42
|
+
end
|
43
|
+
|
44
|
+
def db_instances_to_entities(db_instances)
|
45
|
+
entities = Array(db_instances).map { |db_instance| db_instance_to_entity(db_instance) }
|
46
|
+
entities.length > 1 ? entities : entities.first
|
47
|
+
end
|
48
|
+
|
49
|
+
def db_instance_to_entity(db_instance)
|
50
|
+
entity = entity_class.new(db_instance.attributes)
|
51
|
+
run_hook :after_conversion, entity, db_instance
|
52
|
+
entity
|
53
|
+
end
|
48
54
|
end
|
49
55
|
end
|
@@ -12,31 +12,35 @@ describe Gummi::RepositoryLayer::Repository do
|
|
12
12
|
it 'is included' do
|
13
13
|
repository_class.should respond_to :db_class
|
14
14
|
repository_class.should respond_to :entity_class
|
15
|
-
repository_class.should respond_to :db_instance_to_entity
|
15
|
+
repository_class.new.should respond_to :db_instance_to_entity
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
describe '.get', elastic: true do
|
20
|
+
|
21
|
+
let (:people) { People.new }
|
22
|
+
|
20
23
|
context 'existing record' do
|
21
24
|
let (:db_person) { DB::Person.create name: 'Buzz Lightyear' }
|
22
25
|
|
23
26
|
it 'return an entity' do
|
24
|
-
person =
|
27
|
+
person = people.get(db_person.id)
|
25
28
|
person.id.should == db_person.id
|
26
29
|
end
|
27
30
|
end
|
28
31
|
|
29
32
|
context 'missing record' do
|
30
33
|
it 'returns nil' do
|
31
|
-
person =
|
34
|
+
person = people.get 'missing_id'
|
32
35
|
person.should be_nil
|
33
36
|
end
|
34
37
|
end
|
35
38
|
end
|
36
39
|
|
37
40
|
describe '.search', elastic: true do
|
38
|
-
let(:
|
39
|
-
let(:
|
41
|
+
let (:people) { People.new }
|
42
|
+
let(:buzz) { DB::Person.create name: 'Buzz Lightyear' }
|
43
|
+
let(:woody) { DB::Person.create name: 'Woody' }
|
40
44
|
|
41
45
|
before do
|
42
46
|
buzz && woody
|
@@ -44,12 +48,12 @@ describe Gummi::RepositoryLayer::Repository do
|
|
44
48
|
end
|
45
49
|
|
46
50
|
it 'sorts correctly' do
|
47
|
-
|
48
|
-
|
51
|
+
people.search(sort: { name: :asc }).records.map(&:name).should == [buzz.name, woody.name]
|
52
|
+
people.search(sort: { name: :desc }).records.map(&:name).should == [woody.name, buzz.name]
|
49
53
|
end
|
50
54
|
|
51
55
|
it 'finds the correct documents' do
|
52
|
-
result =
|
56
|
+
result = people.search do |search|
|
53
57
|
search.query_string = 'Woody'
|
54
58
|
search.facets[:names] = { terms: { field: :name, all_terms: true, size: 100 } }
|
55
59
|
end
|
@@ -59,7 +63,7 @@ describe Gummi::RepositoryLayer::Repository do
|
|
59
63
|
end
|
60
64
|
|
61
65
|
it 'converts the result to entities' do
|
62
|
-
result =
|
66
|
+
result = people.search do |search|
|
63
67
|
search.query_string = 'Woody'
|
64
68
|
end
|
65
69
|
woody = result.records.first
|
@@ -52,9 +52,10 @@ describe Repobahn::Repository do
|
|
52
52
|
let(:db1) { DB::City.new name: 'New York' }
|
53
53
|
let(:db2) { DB::City.new name: 'Boston' }
|
54
54
|
let(:dbs) { [db1, db2] }
|
55
|
+
let(:cities) { Cities.new }
|
55
56
|
|
56
57
|
it 'converts DB instances to Entities' do
|
57
|
-
entities =
|
58
|
+
entities = cities.db_instances_to_entities dbs
|
58
59
|
entities.size.should == 2
|
59
60
|
entities.first.should be_instance_of City
|
60
61
|
entities.second.should be_instance_of City
|
@@ -63,7 +64,7 @@ describe Repobahn::Repository do
|
|
63
64
|
end
|
64
65
|
|
65
66
|
it 'returns a single Entity if a single DB instance is passed in' do
|
66
|
-
entity =
|
67
|
+
entity = cities.db_instances_to_entities db1
|
67
68
|
entity.should be_instance_of City
|
68
69
|
entity.name.should == 'New York'
|
69
70
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gummi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-12-
|
12
|
+
date: 2013-12-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: virtus
|
@@ -232,7 +232,6 @@ files:
|
|
232
232
|
- lib/gummi/version.rb
|
233
233
|
- lib/repobahn/entity.rb
|
234
234
|
- lib/repobahn/repository.rb
|
235
|
-
- lib/repobahn/repository/active_record.rb
|
236
235
|
- spec/lib/gummi/db_layer/document_spec.rb
|
237
236
|
- spec/lib/gummi/entity_layer/entity_spec.rb
|
238
237
|
- spec/lib/gummi/repository_layer/repository_spec.rb
|
@@ -270,12 +269,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
270
269
|
- - ! '>='
|
271
270
|
- !ruby/object:Gem::Version
|
272
271
|
version: '0'
|
272
|
+
segments:
|
273
|
+
- 0
|
274
|
+
hash: 1073963271275319698
|
273
275
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
274
276
|
none: false
|
275
277
|
requirements:
|
276
278
|
- - ! '>='
|
277
279
|
- !ruby/object:Gem::Version
|
278
280
|
version: '0'
|
281
|
+
segments:
|
282
|
+
- 0
|
283
|
+
hash: 1073963271275319698
|
279
284
|
requirements: []
|
280
285
|
rubyforge_project:
|
281
286
|
rubygems_version: 1.8.23
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module Repobahn
|
2
|
-
module Repository
|
3
|
-
module ActiveRecord
|
4
|
-
extend ActiveSupport::Concern
|
5
|
-
|
6
|
-
module ClassMethods
|
7
|
-
|
8
|
-
def find(id)
|
9
|
-
record = document_class.find id.to_i
|
10
|
-
document_to_entity record if record
|
11
|
-
end
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|