gummi 1.0.0 → 1.0.2

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.
data/bin/console CHANGED
@@ -6,9 +6,9 @@ $: << ::File.expand_path('../..', __FILE__)
6
6
 
7
7
  require 'pry'
8
8
  require 'lib/gummi'
9
- require 'spec/models/db/person'
10
- require 'spec/models/person'
11
- require 'spec/models/people'
9
+ require 'spec/support/models/db/person'
10
+ require 'spec/support/models/person'
11
+ require 'spec/support/models/people'
12
12
  RAILS_ENV = ENV['RAILS_ENV'] || 'development'
13
13
 
14
14
  def reload!
@@ -18,4 +18,4 @@ def reload!
18
18
  end
19
19
 
20
20
  Pry.config.prompt = [ proc { "gummi >> " }, proc { "... >> " }]
21
- Pry.start
21
+ Pry.start
@@ -18,6 +18,16 @@ module Gummi
18
18
  # Public Persistence API
19
19
  # ––––––––––––––––––––––
20
20
 
21
+ # Public: Checks if specified document exists
22
+ #
23
+ # id - The document id
24
+ #
25
+ # Examples
26
+ #
27
+ # DB::Person.exists?('123')
28
+ # # => true
29
+ #
30
+ # Returns true or false
21
31
  def exists?(id)
22
32
  client.exists index: index.name, type: document_type, id: id
23
33
  end
@@ -27,11 +37,21 @@ module Gummi
27
37
  instance.create ? instance : nil
28
38
  end
29
39
 
30
- def get(*args)
31
- get! *args
40
+ def get(id, parent_id = nil)
41
+ options = { index: index.name, type: document_type, id: id, fields: %w{ _source _parent } }
42
+ if parent_id
43
+ options.merge! parent: parent_id
44
+ elsif parent_document_type
45
+ raise ArgumentError, "The parent_id attribute is required for getting #{name} from Elastic Search"
46
+ end
47
+ response = ActiveSupport::Notifications.instrument "search.elasticsearch", name: "Document#get", search: options do
48
+ Hashie::Mash.new client.get options
49
+ end
50
+ hit_to_document response
32
51
  rescue ::Elasticsearch::Transport::Transport::Errors::NotFound
33
52
  nil
34
53
  end
54
+ alias :find :get
35
55
 
36
56
  def delete(*args)
37
57
  delete! *args
@@ -46,8 +66,10 @@ module Gummi
46
66
  else
47
67
  options = {}
48
68
  end
49
- response = Hashie::Mash.new client.update options.merge(index: index.name, type: document_type, id: id, body: { doc: attributes })
50
- response.ok
69
+ client.update options.merge(index: index.name, type: document_type, id: id, body: { doc: attributes })
70
+ true
71
+ rescue ::Elasticsearch::Transport::Transport::Errors::NotFound
72
+ nil
51
73
  end
52
74
 
53
75
  def delete_children_by_query(parent_id, children_query)
@@ -165,18 +187,6 @@ module Gummi
165
187
  # Internal Persistence API
166
188
  # ––––––––––––––––––––––––
167
189
 
168
- def get!(id, parent_id = nil)
169
- options = { index: index.name, type: document_type, id: id, fields: %w{ _source _parent } }
170
- if parent_id
171
- options.merge! parent: parent_id
172
- elsif parent_document_type
173
- raise ArgumentError, "The parent_id attribute is required for getting #{name} from Elastic Search"
174
- end
175
- response = ActiveSupport::Notifications.instrument "search.elasticsearch", name: "Document#get!", search: options do
176
- Hashie::Mash.new client.get options
177
- end
178
- hit_to_document response
179
- end
180
190
 
181
191
  def delete!(id, parent_id = nil)
182
192
  options = { index: index.name, type: document_type, id: id }
@@ -188,7 +198,7 @@ module Gummi
188
198
  response = ActiveSupport::Notifications.instrument "search.elasticsearch", name: "Document#delete!", search: options do
189
199
  Hashie::Mash.new client.delete options
190
200
  end
191
- response.ok && response.found
201
+ response.found
192
202
  end
193
203
 
194
204
  end
data/lib/gummi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Gummi
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.2'
3
3
  end
@@ -1,5 +1,5 @@
1
- require 'db/person'
2
- require 'person'
1
+ require_relative 'db/person'
2
+ require_relative 'person'
3
3
 
4
4
  class People
5
5
  include Gummi::RepositoryLayer::Repository
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: 1.0.0
4
+ version: 1.0.2
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: 2014-03-14 00:00:00.000000000 Z
12
+ date: 2014-03-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: virtus
@@ -274,18 +274,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
274
274
  - - ! '>='
275
275
  - !ruby/object:Gem::Version
276
276
  version: '0'
277
- segments:
278
- - 0
279
- hash: 3914732375805973470
280
277
  required_rubygems_version: !ruby/object:Gem::Requirement
281
278
  none: false
282
279
  requirements:
283
280
  - - ! '>='
284
281
  - !ruby/object:Gem::Version
285
282
  version: '0'
286
- segments:
287
- - 0
288
- hash: 3914732375805973470
289
283
  requirements: []
290
284
  rubyforge_project:
291
285
  rubygems_version: 1.8.23
@@ -317,3 +311,4 @@ test_files:
317
311
  - spec/support/models/db/ship.rb
318
312
  - spec/support/models/people.rb
319
313
  - spec/support/models/person.rb
314
+ has_rdoc: