gummi 0.1.2 → 0.2.0

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.
Files changed (79) hide show
  1. data/.gitignore +1 -0
  2. data/gummi.gemspec +7 -6
  3. data/lib/gummi.rb +32 -26
  4. data/lib/gummi/api.rb +3 -1
  5. data/lib/gummi/db_layer/default_index.rb +15 -0
  6. data/lib/gummi/db_layer/document.rb +206 -0
  7. data/lib/gummi/db_layer/document/attributes.rb +40 -0
  8. data/lib/gummi/db_layer/document/object.rb +15 -0
  9. data/lib/gummi/db_layer/document/search/filtered.rb +42 -0
  10. data/lib/gummi/db_layer/document/search/raw.rb +12 -0
  11. data/lib/gummi/db_layer/document/search/result.rb +34 -0
  12. data/lib/gummi/db_layer/document/search/searching.rb +51 -0
  13. data/lib/gummi/db_layer/fields/boolean.rb +13 -0
  14. data/lib/gummi/db_layer/fields/integer.rb +16 -0
  15. data/lib/gummi/db_layer/fields/keyword.rb +15 -0
  16. data/lib/gummi/db_layer/fields/ngram_and_plain.rb +20 -0
  17. data/lib/gummi/db_layer/fields/path_hierarchy.rb +15 -0
  18. data/lib/gummi/db_layer/fields/positive_integer.rb +21 -0
  19. data/lib/gummi/db_layer/fields/sanitized_string.rb +30 -0
  20. data/lib/gummi/db_layer/fields/string.rb +17 -0
  21. data/lib/gummi/db_layer/fields/time.rb +17 -0
  22. data/lib/gummi/db_layer/index.rb +150 -0
  23. data/lib/gummi/entity_layer/entity.rb +22 -0
  24. data/lib/gummi/errors.rb +7 -0
  25. data/lib/gummi/repository_layer/repository.rb +39 -0
  26. data/lib/gummi/repository_layer/repository/result.rb +42 -0
  27. data/lib/gummi/version.rb +1 -1
  28. data/lib/repobahn/repository.rb +25 -33
  29. data/lib/repobahn/repository/active_record.rb +17 -0
  30. data/spec/fixtures/admin/auto.rb +6 -0
  31. data/spec/fixtures/admin/cars.rb +12 -0
  32. data/spec/fixtures/admin/countries.rb +9 -0
  33. data/spec/fixtures/admin/country.rb +6 -0
  34. data/spec/fixtures/admin/db/country.rb +7 -0
  35. data/spec/fixtures/admin/db/vehicle.rb +7 -0
  36. data/spec/fixtures/cities.rb +7 -0
  37. data/spec/fixtures/city.rb +6 -0
  38. data/spec/fixtures/db/animal.rb +9 -0
  39. data/spec/fixtures/db/boat.rb +9 -0
  40. data/spec/fixtures/db/car.rb +9 -0
  41. data/spec/fixtures/db/city.rb +8 -0
  42. data/spec/fixtures/db/enemy.rb +10 -0
  43. data/spec/fixtures/db/game.rb +7 -0
  44. data/spec/fixtures/db/person.rb +15 -0
  45. data/spec/fixtures/db/rating.rb +11 -0
  46. data/spec/fixtures/db/ship.rb +18 -0
  47. data/spec/{models → fixtures}/people.rb +6 -2
  48. data/spec/{models → fixtures}/person.rb +3 -2
  49. data/spec/lib/gummi/db_layer/document_spec.rb +124 -0
  50. data/spec/lib/gummi/{entity_spec.rb → entity_layer/entity_spec.rb} +3 -1
  51. data/spec/lib/gummi/repository_layer/repository_spec.rb +63 -0
  52. data/spec/lib/repobahn/repository_spec.rb +72 -0
  53. data/spec/spec_helper.rb +37 -9
  54. metadata +87 -37
  55. data/lib/gummi/default_index.rb +0 -13
  56. data/lib/gummi/document.rb +0 -139
  57. data/lib/gummi/document/attributes.rb +0 -28
  58. data/lib/gummi/document/object.rb +0 -12
  59. data/lib/gummi/document/search/filtered.rb +0 -39
  60. data/lib/gummi/document/search/raw.rb +0 -9
  61. data/lib/gummi/document/search/result.rb +0 -25
  62. data/lib/gummi/document/search/searching.rb +0 -45
  63. data/lib/gummi/entity.rb +0 -20
  64. data/lib/gummi/fields/boolean.rb +0 -10
  65. data/lib/gummi/fields/integer.rb +0 -14
  66. data/lib/gummi/fields/keyword.rb +0 -13
  67. data/lib/gummi/fields/ngram_and_plain.rb +0 -18
  68. data/lib/gummi/fields/path_hierarchy.rb +0 -13
  69. data/lib/gummi/fields/positive_integer.rb +0 -19
  70. data/lib/gummi/fields/sanitized_string.rb +0 -28
  71. data/lib/gummi/fields/string.rb +0 -15
  72. data/lib/gummi/fields/time.rb +0 -15
  73. data/lib/gummi/index.rb +0 -146
  74. data/lib/gummi/repository.rb +0 -38
  75. data/lib/gummi/repository/result.rb +0 -30
  76. data/spec/lib/gummi/document_spec.rb +0 -73
  77. data/spec/lib/gummi/repository/result_spec.rb +0 -18
  78. data/spec/lib/gummi/repository_spec.rb +0 -81
  79. data/spec/models/db/person.rb +0 -15
@@ -1,6 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Gummi::Entity do
3
+ require 'person'
4
+
5
+ describe Gummi::EntityLayer::Entity do
4
6
 
5
7
  context 'comparison' do
6
8
  let(:car) { Person::Car.new model: 'Blues Mobile' }
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ require 'people'
4
+
5
+ describe Gummi::RepositoryLayer::Repository do
6
+
7
+ let(:repository_class) { People }
8
+ let(:entity_class) { Person }
9
+ let(:db_class) { DB::Person }
10
+
11
+ describe 'Repobahn' do
12
+ it 'is included' do
13
+ repository_class.should respond_to :db_class
14
+ repository_class.should respond_to :entity_class
15
+ repository_class.should respond_to :db_instance_to_entity
16
+ end
17
+ end
18
+
19
+ describe '.get' do
20
+ context 'existing record' do
21
+ let (:db_person) { DB::Person.create name: 'Buzz Lightyear' }
22
+
23
+ it 'return an entity' do
24
+ person = People.get(db_person.id)
25
+ person.id.should == db_person.id
26
+ end
27
+ end
28
+
29
+ context 'missing record' do
30
+ it 'returns nil' do
31
+ person = People.get 'missing_id'
32
+ person.should be_nil
33
+ end
34
+ end
35
+ end
36
+
37
+ describe '.search' do
38
+
39
+ before do
40
+ DB::Person.create name: 'Buzz Lightyear'
41
+ DB::Person.create name: 'Woody'
42
+ Gummi::DbLayer::DefaultIndex.refresh
43
+ end
44
+
45
+ it 'finds the correct documents' do
46
+ result = People.search do |search|
47
+ search.query_string = 'Woody'
48
+ end
49
+ result.total.should == 1
50
+ result.records.first.name.should == 'Woody'
51
+ end
52
+
53
+ it 'converts the result to entities' do
54
+ result = People.search do |search|
55
+ search.query_string = 'Woody'
56
+ end
57
+ woody = result.records.first
58
+ woody.converted_name.should == 'ydooW'
59
+ woody.should be_a Person
60
+ end
61
+ end
62
+
63
+ end
@@ -0,0 +1,72 @@
1
+ require 'spec_helper'
2
+
3
+ require 'cities'
4
+ require 'admin/countries'
5
+ require 'admin/cars'
6
+
7
+ describe Repobahn::Repository do
8
+
9
+ context 'in the root namespace' do
10
+ describe '#db_class' do
11
+ it 'defaults to the singular version in the DB namespace' do
12
+ Cities.db_class.should == DB::City
13
+ end
14
+ end
15
+
16
+ describe '#entity_class' do
17
+ it 'defaults to the singular version' do
18
+ Cities.entity_class.should == City
19
+ end
20
+ end
21
+ end
22
+
23
+ context 'in a custom namespace' do
24
+ describe '#db_class' do
25
+ it 'defaults to the singular version in the DB namespace' do
26
+ Admin::Countries.db_class.should == Admin::DB::Country
27
+ end
28
+ end
29
+
30
+ describe '#entity_class' do
31
+ it 'defaults to the singular version' do
32
+ Admin::Countries.entity_class.should == Admin::Country
33
+ end
34
+ end
35
+ end
36
+
37
+ context 'with custom document/entity class definitions' do
38
+ describe '#db_class' do
39
+ it 'defaults to the singular version in the DB namespace' do
40
+ Admin::Cars.db_class.should == Admin::DB::Vehicle
41
+ end
42
+ end
43
+
44
+ describe '#entity_class' do
45
+ it 'defaults to the singular version' do
46
+ Admin::Cars.entity_class.should == Admin::Auto
47
+ end
48
+ end
49
+ end
50
+
51
+ describe '#db_instances_to_entities' do
52
+ let(:db1) { DB::City.new name: 'New York' }
53
+ let(:db2) { DB::City.new name: 'Boston' }
54
+ let(:dbs) { [db1, db2] }
55
+
56
+ it 'converts DB instances to Entities' do
57
+ entities = Cities.db_instances_to_entities dbs
58
+ entities.size.should == 2
59
+ entities.first.should be_instance_of City
60
+ entities.second.should be_instance_of City
61
+ entities.first.name.should == 'New York'
62
+ entities.second.name.should == 'Boston'
63
+ end
64
+
65
+ it 'returns a single Entity if a single DB instance is passed in' do
66
+ entity = Cities.db_instances_to_entities db1
67
+ entity.should be_instance_of City
68
+ entity.name.should == 'New York'
69
+ end
70
+ end
71
+
72
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,19 +1,47 @@
1
- require "codeclimate-test-reporter"
2
- CodeClimate::TestReporter.start
3
-
4
1
  RAILS_ENV = 'test'
2
+
3
+ # –––––––––––––
4
+ # Test Coverage
5
+ # –––––––––––––
6
+
7
+ if ENV['TRAVIS']
8
+ require "codeclimate-test-reporter"
9
+ CodeClimate::TestReporter.start
10
+ allow_external_requests_to = Regexp.new(ENV['CODECLIMATE_API_HOST'].to_s)
11
+ else
12
+ require 'simplecov'
13
+ SimpleCov.start :rails do
14
+ add_group 'Decorators', 'app/decorators'
15
+ add_group 'Workers', 'app/workers'
16
+ add_group 'Core Extensions', 'lib/extensions/core_extensions'
17
+ add_group 'Rails Extensions', 'lib/extensions/rails_extensions'
18
+
19
+ add_filter '/vendor'
20
+ add_filter '/config/'
21
+ end
22
+ end
23
+
24
+ # ––––––––––––
25
+ # Dependencies
26
+ # ––––––––––––
27
+
28
+ $LOAD_PATH.unshift File.expand_path('../fixtures', __FILE__)
29
+
5
30
  require 'gummi'
6
- require_relative 'models/people'
7
- require_relative 'models/person'
8
- require_relative 'models/db/person'
31
+
32
+ require 'db/person'
33
+ require 'db/rating'
34
+ require 'db/ship'
9
35
 
10
36
  RSpec.configure do |config|
11
37
  config.before(:suite) do
12
- Gummi::DefaultIndex.setup
38
+ Gummi::DbLayer::DefaultIndex.setup
13
39
  DB::Person.sync_mapping!
40
+ DB::Rating.sync_mapping!
41
+ DB::Ship.sync_mapping!
14
42
  end
15
43
 
16
44
  config.after(:suite) do
17
- Gummi::DefaultIndex.teardown
45
+ Gummi::DbLayer::DefaultIndex.teardown
18
46
  end
19
- end
47
+ 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.1.2
4
+ version: 0.2.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-03 00:00:00.000000000 Z
12
+ date: 2013-12-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: virtus
@@ -107,6 +107,22 @@ dependencies:
107
107
  - - ! '>='
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: hashie
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: 2.0.0
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: 2.0.0
110
126
  - !ruby/object:Gem::Dependency
111
127
  name: bundler
112
128
  requirement: !ruby/object:Gem::Requirement
@@ -190,37 +206,55 @@ files:
190
206
  - gummi.gemspec
191
207
  - lib/gummi.rb
192
208
  - lib/gummi/api.rb
193
- - lib/gummi/default_index.rb
194
- - lib/gummi/document.rb
195
- - lib/gummi/document/attributes.rb
196
- - lib/gummi/document/object.rb
197
- - lib/gummi/document/search/filtered.rb
198
- - lib/gummi/document/search/raw.rb
199
- - lib/gummi/document/search/result.rb
200
- - lib/gummi/document/search/searching.rb
201
- - lib/gummi/entity.rb
202
- - lib/gummi/fields/boolean.rb
203
- - lib/gummi/fields/integer.rb
204
- - lib/gummi/fields/keyword.rb
205
- - lib/gummi/fields/ngram_and_plain.rb
206
- - lib/gummi/fields/path_hierarchy.rb
207
- - lib/gummi/fields/positive_integer.rb
208
- - lib/gummi/fields/sanitized_string.rb
209
- - lib/gummi/fields/string.rb
210
- - lib/gummi/fields/time.rb
211
- - lib/gummi/index.rb
212
- - lib/gummi/repository.rb
213
- - lib/gummi/repository/result.rb
209
+ - lib/gummi/db_layer/default_index.rb
210
+ - lib/gummi/db_layer/document.rb
211
+ - lib/gummi/db_layer/document/attributes.rb
212
+ - lib/gummi/db_layer/document/object.rb
213
+ - lib/gummi/db_layer/document/search/filtered.rb
214
+ - lib/gummi/db_layer/document/search/raw.rb
215
+ - lib/gummi/db_layer/document/search/result.rb
216
+ - lib/gummi/db_layer/document/search/searching.rb
217
+ - lib/gummi/db_layer/fields/boolean.rb
218
+ - lib/gummi/db_layer/fields/integer.rb
219
+ - lib/gummi/db_layer/fields/keyword.rb
220
+ - lib/gummi/db_layer/fields/ngram_and_plain.rb
221
+ - lib/gummi/db_layer/fields/path_hierarchy.rb
222
+ - lib/gummi/db_layer/fields/positive_integer.rb
223
+ - lib/gummi/db_layer/fields/sanitized_string.rb
224
+ - lib/gummi/db_layer/fields/string.rb
225
+ - lib/gummi/db_layer/fields/time.rb
226
+ - lib/gummi/db_layer/index.rb
227
+ - lib/gummi/entity_layer/entity.rb
228
+ - lib/gummi/errors.rb
229
+ - lib/gummi/repository_layer/repository.rb
230
+ - lib/gummi/repository_layer/repository/result.rb
214
231
  - lib/gummi/version.rb
215
232
  - lib/repobahn/entity.rb
216
233
  - lib/repobahn/repository.rb
217
- - spec/lib/gummi/document_spec.rb
218
- - spec/lib/gummi/entity_spec.rb
219
- - spec/lib/gummi/repository/result_spec.rb
220
- - spec/lib/gummi/repository_spec.rb
221
- - spec/models/db/person.rb
222
- - spec/models/people.rb
223
- - spec/models/person.rb
234
+ - lib/repobahn/repository/active_record.rb
235
+ - spec/fixtures/admin/auto.rb
236
+ - spec/fixtures/admin/cars.rb
237
+ - spec/fixtures/admin/countries.rb
238
+ - spec/fixtures/admin/country.rb
239
+ - spec/fixtures/admin/db/country.rb
240
+ - spec/fixtures/admin/db/vehicle.rb
241
+ - spec/fixtures/cities.rb
242
+ - spec/fixtures/city.rb
243
+ - spec/fixtures/db/animal.rb
244
+ - spec/fixtures/db/boat.rb
245
+ - spec/fixtures/db/car.rb
246
+ - spec/fixtures/db/city.rb
247
+ - spec/fixtures/db/enemy.rb
248
+ - spec/fixtures/db/game.rb
249
+ - spec/fixtures/db/person.rb
250
+ - spec/fixtures/db/rating.rb
251
+ - spec/fixtures/db/ship.rb
252
+ - spec/fixtures/people.rb
253
+ - spec/fixtures/person.rb
254
+ - spec/lib/gummi/db_layer/document_spec.rb
255
+ - spec/lib/gummi/entity_layer/entity_spec.rb
256
+ - spec/lib/gummi/repository_layer/repository_spec.rb
257
+ - spec/lib/repobahn/repository_spec.rb
224
258
  - spec/spec_helper.rb
225
259
  homepage: ''
226
260
  licenses:
@@ -248,11 +282,27 @@ signing_key:
248
282
  specification_version: 3
249
283
  summary: A small wrapper around Elasticsearch
250
284
  test_files:
251
- - spec/lib/gummi/document_spec.rb
252
- - spec/lib/gummi/entity_spec.rb
253
- - spec/lib/gummi/repository/result_spec.rb
254
- - spec/lib/gummi/repository_spec.rb
255
- - spec/models/db/person.rb
256
- - spec/models/people.rb
257
- - spec/models/person.rb
285
+ - spec/fixtures/admin/auto.rb
286
+ - spec/fixtures/admin/cars.rb
287
+ - spec/fixtures/admin/countries.rb
288
+ - spec/fixtures/admin/country.rb
289
+ - spec/fixtures/admin/db/country.rb
290
+ - spec/fixtures/admin/db/vehicle.rb
291
+ - spec/fixtures/cities.rb
292
+ - spec/fixtures/city.rb
293
+ - spec/fixtures/db/animal.rb
294
+ - spec/fixtures/db/boat.rb
295
+ - spec/fixtures/db/car.rb
296
+ - spec/fixtures/db/city.rb
297
+ - spec/fixtures/db/enemy.rb
298
+ - spec/fixtures/db/game.rb
299
+ - spec/fixtures/db/person.rb
300
+ - spec/fixtures/db/rating.rb
301
+ - spec/fixtures/db/ship.rb
302
+ - spec/fixtures/people.rb
303
+ - spec/fixtures/person.rb
304
+ - spec/lib/gummi/db_layer/document_spec.rb
305
+ - spec/lib/gummi/entity_layer/entity_spec.rb
306
+ - spec/lib/gummi/repository_layer/repository_spec.rb
307
+ - spec/lib/repobahn/repository_spec.rb
258
308
  - spec/spec_helper.rb
@@ -1,13 +0,0 @@
1
- module Gummi
2
- class DefaultIndex
3
- include Gummi::Index
4
-
5
- def self.name
6
- if defined? Rails
7
- "#{Rails.application.class.name.deconstantize.underscore}_#{Rails.env}"
8
- else
9
- "gummi_#{Gummi.env}"
10
- end
11
- end
12
- end
13
- end
@@ -1,139 +0,0 @@
1
- module Gummi
2
- module Document
3
- extend ActiveSupport::Concern
4
-
5
- included do
6
- include Virtus.model
7
- include Gummi::Document::Attributes
8
- end
9
-
10
- attr_accessor :id
11
- attr_accessor :version
12
-
13
- def overwrite
14
- response = client.index index: index.name, type: document_type, id: id, body: attributes
15
- if response["ok"]
16
- self.version = response["_version"]
17
- self.id = response["_id"]
18
- true
19
- else
20
- false
21
- end
22
- end
23
-
24
- def create
25
- response = client.create index: index.name, type: document_type, id: id, body: attributes
26
- if response["ok"]
27
- self.version = response["_version"]
28
- self.id = response["_id"]
29
- true
30
- else
31
- false
32
- end
33
- end
34
-
35
- def update
36
- response = client.update index: index.name, type: document_type, id: id, retry_on_conflict: 0, version: version, body: { doc: attributes.as_json }
37
- if response["ok"]
38
- self.version = response["_version"]
39
- true
40
- else
41
- false
42
- end
43
- end
44
-
45
- private
46
-
47
- def client
48
- Gummi::API.client
49
- end
50
-
51
- def document_type
52
- self.class.document_type
53
- end
54
-
55
- def index
56
- self.class.index
57
- end
58
-
59
- module ClassMethods
60
-
61
- def create(attributes)
62
- document = self.new(attributes)
63
- response = client.create index: index.name, type: document_type, id: document.id, body: document.attributes
64
- if response["ok"]
65
- document.version = response["_version"]
66
- document.id = response["_id"]
67
- document
68
- end
69
- end
70
-
71
- def get!(id)
72
- response = client.get index: index.name, type: document_type, id: id
73
- doc_hash = {id: response["_id"], version: response["_version"]}.merge(response["_source"])
74
- lot = self.new(doc_hash)
75
- lot.version = response["_version"]
76
- lot
77
- end
78
-
79
- def get(id)
80
- get!(id)
81
- rescue ::Elasticsearch::Transport::Transport::Errors::NotFound
82
- nil
83
- end
84
-
85
- def document_type(type_name)
86
- @document_type = type_name
87
- end
88
-
89
- def document_type
90
- @document_type || name.split('::').last.underscore
91
- end
92
-
93
- def index
94
- @index || Gummi::DefaultIndex
95
- end
96
-
97
- def index=(index)
98
- @index = index
99
- end
100
-
101
- def parent_document_type
102
- nil
103
- end
104
-
105
- def sync_mapping!
106
- client.indices.put_mapping creation_options
107
- end
108
-
109
- def new_filtered_search(options = {})
110
- args = {}
111
- args[:index] = index.name
112
- args[:type] = document_type
113
- args.merge! options
114
-
115
- Gummi::Document::Search::Filtered.new args
116
- end
117
-
118
- def creation_options
119
- result = {
120
- index: index.name,
121
- type: document_type,
122
- body: {
123
- document_type => {
124
- properties: mapping,
125
- }
126
- }
127
- }
128
- result[:body][document_type].merge!(_parent: { type: parent_document_type }) if parent_document_type.present?
129
- result
130
- end
131
-
132
- private
133
-
134
- def client
135
- Gummi::API.client
136
- end
137
- end
138
- end
139
- end