gummi 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,36 +8,32 @@ module Gummi
8
8
  after_conversion :set_id_and_version
9
9
  end
10
10
 
11
- module ClassMethods
12
-
13
- def get(id)
14
- document = db_class.get id
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
- def raw_search(options = {}, &block)
25
- search = db_class.new_raw_search(options)
26
- yield search if block_given?
27
- Repository::Result.new search.execute, self
28
- end
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
- def overwrite(entity)
31
- return false unless entity.valid?
32
- document = db_class.new(entity.attributes)
33
- document.overwrite
34
- end
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
- def set_id_and_version(entity, db_instance)
37
- entity.id = db_instance.id
38
- entity.version = db_instance.version
39
- end
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
@@ -1,3 +1,3 @@
1
1
  module Gummi
2
- VERSION = '0.2.3'
2
+ VERSION = '0.3.0'
3
3
  end
data/lib/gummi.rb CHANGED
@@ -6,7 +6,6 @@ require 'hooks'
6
6
  require 'leaflet'
7
7
  require 'hashie/mash'
8
8
 
9
- require 'repobahn/repository/active_record'
10
9
  require 'repobahn/repository'
11
10
  require 'repobahn/entity'
12
11
 
@@ -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 = People.get(db_person.id)
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 = People.get 'missing_id'
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(:buzz) { DB::Person.create name: 'Buzz Lightyear' }
39
- let(:woody) { DB::Person.create name: 'Woody' }
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
- People.search(sort: { name: :asc }).records.map(&:name).should == [buzz.name, woody.name]
48
- People.search(sort: { name: :desc }).records.map(&:name).should == [woody.name, buzz.name]
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 = People.search do |search|
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 = People.search do |search|
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 = Cities.db_instances_to_entities dbs
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 = Cities.db_instances_to_entities db1
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
@@ -6,7 +6,7 @@ class People
6
6
 
7
7
  after_conversion :convert_name
8
8
 
9
- def self.convert_name(entity, db)
9
+ def convert_name(entity, db)
10
10
  entity.converted_name = db.name.reverse
11
11
  end
12
12
 
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.2.3
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-27 00:00:00.000000000 Z
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