elastic_record 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,20 +1,39 @@
1
- Expects that your model implements find(*ids)
1
+ = ElasticRecord
2
2
 
3
- class Widgets
3
+ ElasticRecord is an elasticsearch ORM.
4
+
5
+ == Setup
6
+
7
+ The usual Gemfile addition:
8
+
9
+ gem 'elastic_record'
10
+
11
+ Creating the index:
12
+
13
+ rake index:create
14
+
15
+ Include ElasticRecord into your model:
16
+
17
+ ActiveSupport.on_load :active_record do
4
18
  include ElasticRecord::Model
5
19
  end
6
20
 
7
- scope = Widgets.filter(color: 'red').order(:price)
21
+ == Querying:
8
22
 
23
+ scope = Product.elastic_search
24
+
25
+ scope.filter(color: 'red')
26
+ scope.order(:price)
9
27
  scope.count
10
28
  scope.first
11
- scope.last
12
29
  scope.all
13
- scope.each
30
+ scope.each do |product|
31
+ ...
32
+ end
14
33
 
15
34
  Class methods are executed within scopes:
16
35
 
17
- class Widgets
36
+ class Pirate
18
37
  def self.ouput_to_screen
19
38
  all.each do { |widget| puts widget }
20
39
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'elastic_record'
5
- s.version = '0.3.1'
5
+ s.version = '0.4.0'
6
6
  s.summary = 'Use Elastic Search with your objects'
7
7
  s.description = 'Find your records with elastic search'
8
8
 
@@ -3,11 +3,11 @@ module ElasticRecord
3
3
  def self.included(base)
4
4
  base.class_eval do
5
5
  after_save do
6
- elastic_index.index_record self
6
+ self.class.elastic_index.index_record self
7
7
  end
8
8
 
9
9
  after_destroy do
10
- elastic_index.delete_record self
10
+ self.class.elastic_index.delete_record self
11
11
  end
12
12
  end
13
13
  end
@@ -2,9 +2,9 @@ module ElasticRecord
2
2
  module Model
3
3
  def self.included(base)
4
4
  base.class_eval do
5
- extend Connection
6
- extend Searching
7
- extend ClassMethods
5
+ include Callbacks
6
+
7
+ extend Connection, Searching, ClassMethods
8
8
  end
9
9
  end
10
10
 
@@ -1,6 +1,8 @@
1
1
  require 'arelastic'
2
+ require 'rubberband'
2
3
 
3
4
  module ElasticRecord
5
+ autoload :Callbacks, 'elastic_record/callbacks'
4
6
  autoload :Config, 'elastic_record/config'
5
7
  autoload :Connection, 'elastic_record/connection'
6
8
  autoload :Index, 'elastic_record/index'
@@ -0,0 +1,28 @@
1
+ require 'helper'
2
+
3
+ class ElasticRecord::CallbacksTest < MiniTest::Spec
4
+ def setup
5
+ super
6
+ Widget.elastic_index.reset
7
+ end
8
+
9
+ def test_added_to_index
10
+ widget = Widget.new id: '10', color: 'green'
11
+ refute Widget.elastic_index.record_exists?(widget.id)
12
+
13
+ widget.run_callbacks :save
14
+
15
+ assert Widget.elastic_index.record_exists?(widget.id)
16
+ end
17
+
18
+ def test_deleted_from_index
19
+ widget = Widget.new id: '10', color: 'green'
20
+ Widget.elastic_index.index_record(widget)
21
+
22
+ assert Widget.elastic_index.record_exists?(widget.id)
23
+
24
+ widget.run_callbacks :destroy
25
+
26
+ refute Widget.elastic_index.record_exists?(widget.id)
27
+ end
28
+ end
data/test/helper.rb CHANGED
@@ -3,7 +3,6 @@ Bundler.require
3
3
 
4
4
  require 'minitest/autorun'
5
5
 
6
- require 'rubberband'
7
6
  require 'active_support/core_ext/object/blank'
8
7
  require 'active_model'
9
8
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elastic_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -92,6 +92,7 @@ files:
92
92
  - lib/elastic_record/relation/value_methods.rb
93
93
  - lib/elastic_record/searching.rb
94
94
  - lib/elastic_record/tasks/index.rake
95
+ - test/elastic_record/callbacks_test.rb
95
96
  - test/elastic_record/config_test.rb
96
97
  - test/elastic_record/connection_test.rb
97
98
  - test/elastic_record/index/documents_test.rb