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 +25 -6
- data/elastic_record.gemspec +1 -1
- data/lib/elastic_record/callbacks.rb +2 -2
- data/lib/elastic_record/model.rb +3 -3
- data/lib/elastic_record.rb +2 -0
- data/test/elastic_record/callbacks_test.rb +28 -0
- data/test/helper.rb +0 -1
- metadata +2 -1
data/README.rdoc
CHANGED
@@ -1,20 +1,39 @@
|
|
1
|
-
|
1
|
+
= ElasticRecord
|
2
2
|
|
3
|
-
|
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
|
-
|
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
|
36
|
+
class Pirate
|
18
37
|
def self.ouput_to_screen
|
19
38
|
all.each do { |widget| puts widget }
|
20
39
|
end
|
data/elastic_record.gemspec
CHANGED
@@ -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
|
data/lib/elastic_record/model.rb
CHANGED
data/lib/elastic_record.rb
CHANGED
@@ -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
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.
|
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
|