elasticsearch-persistence 5.1.0 → 6.0.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/Gemfile +9 -0
- data/README.md +164 -323
- data/Rakefile +8 -8
- data/elasticsearch-persistence.gemspec +4 -5
- data/lib/elasticsearch/persistence.rb +2 -110
- data/lib/elasticsearch/persistence/repository.rb +212 -53
- data/lib/elasticsearch/persistence/repository/dsl.rb +94 -0
- data/lib/elasticsearch/persistence/repository/find.rb +27 -10
- data/lib/elasticsearch/persistence/repository/response/results.rb +17 -5
- data/lib/elasticsearch/persistence/repository/search.rb +15 -4
- data/lib/elasticsearch/persistence/repository/serialize.rb +65 -7
- data/lib/elasticsearch/persistence/repository/store.rb +38 -44
- data/lib/elasticsearch/persistence/version.rb +1 -1
- data/spec/repository/find_spec.rb +179 -0
- data/spec/repository/response/results_spec.rb +105 -0
- data/spec/repository/search_spec.rb +181 -0
- data/spec/repository/serialize_spec.rb +53 -0
- data/spec/repository/store_spec.rb +327 -0
- data/spec/repository_spec.rb +716 -0
- data/spec/spec_helper.rb +28 -0
- metadata +25 -80
- data/lib/elasticsearch/persistence/client.rb +0 -51
- data/lib/elasticsearch/persistence/model.rb +0 -153
- data/lib/elasticsearch/persistence/model/base.rb +0 -87
- data/lib/elasticsearch/persistence/model/errors.rb +0 -8
- data/lib/elasticsearch/persistence/model/find.rb +0 -180
- data/lib/elasticsearch/persistence/model/rails.rb +0 -47
- data/lib/elasticsearch/persistence/model/store.rb +0 -254
- data/lib/elasticsearch/persistence/model/utils.rb +0 -0
- data/lib/elasticsearch/persistence/repository/class.rb +0 -71
- data/lib/elasticsearch/persistence/repository/naming.rb +0 -115
- data/lib/rails/generators/elasticsearch/model/model_generator.rb +0 -21
- data/lib/rails/generators/elasticsearch/model/templates/model.rb.tt +0 -9
- data/lib/rails/generators/elasticsearch_generator.rb +0 -2
- data/test/integration/model/model_basic_test.rb +0 -238
- data/test/integration/repository/custom_class_test.rb +0 -85
- data/test/integration/repository/customized_class_test.rb +0 -82
- data/test/integration/repository/default_class_test.rb +0 -116
- data/test/integration/repository/virtus_model_test.rb +0 -118
- data/test/test_helper.rb +0 -55
- data/test/unit/model_base_test.rb +0 -72
- data/test/unit/model_find_test.rb +0 -153
- data/test/unit/model_gateway_test.rb +0 -101
- data/test/unit/model_rails_test.rb +0 -112
- data/test/unit/model_store_test.rb +0 -576
- data/test/unit/persistence_test.rb +0 -32
- data/test/unit/repository_class_test.rb +0 -51
- data/test/unit/repository_client_test.rb +0 -32
- data/test/unit/repository_find_test.rb +0 -388
- data/test/unit/repository_indexing_test.rb +0 -37
- data/test/unit/repository_module_test.rb +0 -146
- data/test/unit/repository_naming_test.rb +0 -146
- data/test/unit/repository_response_results_test.rb +0 -98
- data/test/unit/repository_search_test.rb +0 -117
- data/test/unit/repository_serialize_test.rb +0 -57
- data/test/unit/repository_store_test.rb +0 -303
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'pry-nav'
|
2
|
+
require 'elasticsearch/persistence'
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
config.formatter = 'documentation'
|
6
|
+
config.color = true
|
7
|
+
|
8
|
+
config.after(:suite) do
|
9
|
+
DEFAULT_CLIENT.indices.delete(index: '_all')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# The default client to be used by the repositories.
|
14
|
+
#
|
15
|
+
# @since 6.0.0
|
16
|
+
DEFAULT_CLIENT = Elasticsearch::Client.new(host: "localhost:#{(ENV['TEST_CLUSTER_PORT'] || 9250)}",
|
17
|
+
tracer: (ENV['QUIET'] ? nil : ::Logger.new(STDERR)))
|
18
|
+
|
19
|
+
class MyTestRepository
|
20
|
+
include Elasticsearch::Persistence::Repository
|
21
|
+
include Elasticsearch::Persistence::Repository::DSL
|
22
|
+
client DEFAULT_CLIENT
|
23
|
+
end
|
24
|
+
|
25
|
+
# The default repository to be used by tests.
|
26
|
+
#
|
27
|
+
# @since 6.0.0
|
28
|
+
DEFAULT_REPOSITORY = MyTestRepository.new(index_name: 'my_test_repository', document_type: 'test')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elasticsearch-persistence
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 6.0.0.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Karel Minarik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: elasticsearch
|
@@ -16,26 +16,26 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '6'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: elasticsearch-model
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '5'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '5'
|
41
41
|
- !ruby/object:Gem::Dependency
|
@@ -80,20 +80,6 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: virtus
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :runtime
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: bundler
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -314,6 +300,7 @@ extra_rdoc_files:
|
|
314
300
|
- LICENSE.txt
|
315
301
|
files:
|
316
302
|
- ".gitignore"
|
303
|
+
- ".rspec"
|
317
304
|
- CHANGELOG.md
|
318
305
|
- Gemfile
|
319
306
|
- LICENSE.txt
|
@@ -349,48 +336,21 @@ files:
|
|
349
336
|
- examples/notes/config.ru
|
350
337
|
- examples/notes/test.rb
|
351
338
|
- lib/elasticsearch/persistence.rb
|
352
|
-
- lib/elasticsearch/persistence/client.rb
|
353
|
-
- lib/elasticsearch/persistence/model.rb
|
354
|
-
- lib/elasticsearch/persistence/model/base.rb
|
355
|
-
- lib/elasticsearch/persistence/model/errors.rb
|
356
|
-
- lib/elasticsearch/persistence/model/find.rb
|
357
|
-
- lib/elasticsearch/persistence/model/rails.rb
|
358
|
-
- lib/elasticsearch/persistence/model/store.rb
|
359
|
-
- lib/elasticsearch/persistence/model/utils.rb
|
360
339
|
- lib/elasticsearch/persistence/repository.rb
|
361
|
-
- lib/elasticsearch/persistence/repository/
|
340
|
+
- lib/elasticsearch/persistence/repository/dsl.rb
|
362
341
|
- lib/elasticsearch/persistence/repository/find.rb
|
363
|
-
- lib/elasticsearch/persistence/repository/naming.rb
|
364
342
|
- lib/elasticsearch/persistence/repository/response/results.rb
|
365
343
|
- lib/elasticsearch/persistence/repository/search.rb
|
366
344
|
- lib/elasticsearch/persistence/repository/serialize.rb
|
367
345
|
- lib/elasticsearch/persistence/repository/store.rb
|
368
346
|
- lib/elasticsearch/persistence/version.rb
|
369
|
-
-
|
370
|
-
-
|
371
|
-
-
|
372
|
-
-
|
373
|
-
-
|
374
|
-
-
|
375
|
-
-
|
376
|
-
- test/integration/repository/virtus_model_test.rb
|
377
|
-
- test/test_helper.rb
|
378
|
-
- test/unit/model_base_test.rb
|
379
|
-
- test/unit/model_find_test.rb
|
380
|
-
- test/unit/model_gateway_test.rb
|
381
|
-
- test/unit/model_rails_test.rb
|
382
|
-
- test/unit/model_store_test.rb
|
383
|
-
- test/unit/persistence_test.rb
|
384
|
-
- test/unit/repository_class_test.rb
|
385
|
-
- test/unit/repository_client_test.rb
|
386
|
-
- test/unit/repository_find_test.rb
|
387
|
-
- test/unit/repository_indexing_test.rb
|
388
|
-
- test/unit/repository_module_test.rb
|
389
|
-
- test/unit/repository_naming_test.rb
|
390
|
-
- test/unit/repository_response_results_test.rb
|
391
|
-
- test/unit/repository_search_test.rb
|
392
|
-
- test/unit/repository_serialize_test.rb
|
393
|
-
- test/unit/repository_store_test.rb
|
347
|
+
- spec/repository/find_spec.rb
|
348
|
+
- spec/repository/response/results_spec.rb
|
349
|
+
- spec/repository/search_spec.rb
|
350
|
+
- spec/repository/serialize_spec.rb
|
351
|
+
- spec/repository/store_spec.rb
|
352
|
+
- spec/repository_spec.rb
|
353
|
+
- spec/spec_helper.rb
|
394
354
|
homepage: https://github.com/elasticsearch/elasticsearch-rails/
|
395
355
|
licenses:
|
396
356
|
- Apache 2
|
@@ -407,35 +367,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
407
367
|
version: 1.9.3
|
408
368
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
409
369
|
requirements:
|
410
|
-
- - "
|
370
|
+
- - ">"
|
411
371
|
- !ruby/object:Gem::Version
|
412
|
-
version:
|
372
|
+
version: 1.3.1
|
413
373
|
requirements: []
|
414
374
|
rubyforge_project:
|
415
|
-
rubygems_version: 2.7.
|
375
|
+
rubygems_version: 2.7.7
|
416
376
|
signing_key:
|
417
377
|
specification_version: 4
|
418
378
|
summary: Persistence layer for Ruby models and Elasticsearch.
|
419
379
|
test_files:
|
420
|
-
-
|
421
|
-
-
|
422
|
-
-
|
423
|
-
-
|
424
|
-
-
|
425
|
-
-
|
426
|
-
-
|
427
|
-
- test/unit/model_find_test.rb
|
428
|
-
- test/unit/model_gateway_test.rb
|
429
|
-
- test/unit/model_rails_test.rb
|
430
|
-
- test/unit/model_store_test.rb
|
431
|
-
- test/unit/persistence_test.rb
|
432
|
-
- test/unit/repository_class_test.rb
|
433
|
-
- test/unit/repository_client_test.rb
|
434
|
-
- test/unit/repository_find_test.rb
|
435
|
-
- test/unit/repository_indexing_test.rb
|
436
|
-
- test/unit/repository_module_test.rb
|
437
|
-
- test/unit/repository_naming_test.rb
|
438
|
-
- test/unit/repository_response_results_test.rb
|
439
|
-
- test/unit/repository_search_test.rb
|
440
|
-
- test/unit/repository_serialize_test.rb
|
441
|
-
- test/unit/repository_store_test.rb
|
380
|
+
- spec/repository/find_spec.rb
|
381
|
+
- spec/repository/response/results_spec.rb
|
382
|
+
- spec/repository/search_spec.rb
|
383
|
+
- spec/repository/serialize_spec.rb
|
384
|
+
- spec/repository/store_spec.rb
|
385
|
+
- spec/repository_spec.rb
|
386
|
+
- spec/spec_helper.rb
|
@@ -1,51 +0,0 @@
|
|
1
|
-
module Elasticsearch
|
2
|
-
module Persistence
|
3
|
-
module Repository
|
4
|
-
|
5
|
-
# Wraps the Elasticsearch Ruby
|
6
|
-
# [client](https://github.com/elasticsearch/elasticsearch-ruby/tree/master/elasticsearch#usage)
|
7
|
-
#
|
8
|
-
module Client
|
9
|
-
|
10
|
-
# Get or set the default client for this repository
|
11
|
-
#
|
12
|
-
# @example Set and configure the client for the repository class
|
13
|
-
#
|
14
|
-
# class MyRepository
|
15
|
-
# include Elasticsearch::Persistence::Repository
|
16
|
-
# client Elasticsearch::Client.new host: 'http://localhost:9200', log: true
|
17
|
-
# end
|
18
|
-
#
|
19
|
-
# @example Set and configure the client for this repository instance
|
20
|
-
#
|
21
|
-
# repository.client Elasticsearch::Client.new host: 'http://localhost:9200', tracer: true
|
22
|
-
#
|
23
|
-
# @example Perform an API request through the client
|
24
|
-
#
|
25
|
-
# MyRepository.client.cluster.health
|
26
|
-
# repository.client.cluster.health
|
27
|
-
# # => { "cluster_name" => "elasticsearch" ... }
|
28
|
-
#
|
29
|
-
def client client=nil
|
30
|
-
@client = client || @client || Elasticsearch::Persistence.client
|
31
|
-
end
|
32
|
-
|
33
|
-
# Set the default client for this repository
|
34
|
-
#
|
35
|
-
# @example Set and configure the client for the repository class
|
36
|
-
#
|
37
|
-
# MyRepository.client = Elasticsearch::Client.new host: 'http://localhost:9200', log: true
|
38
|
-
#
|
39
|
-
# @example Set and configure the client for this repository instance
|
40
|
-
#
|
41
|
-
# repository.client = Elasticsearch::Client.new host: 'http://localhost:9200', tracer: true
|
42
|
-
#
|
43
|
-
def client=(client)
|
44
|
-
@client = client
|
45
|
-
@client
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
@@ -1,153 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext/module/delegation'
|
2
|
-
|
3
|
-
require 'active_model'
|
4
|
-
require 'virtus'
|
5
|
-
|
6
|
-
require 'elasticsearch/persistence'
|
7
|
-
require 'elasticsearch/persistence/model/base'
|
8
|
-
require 'elasticsearch/persistence/model/errors'
|
9
|
-
require 'elasticsearch/persistence/model/store'
|
10
|
-
require 'elasticsearch/persistence/model/find'
|
11
|
-
|
12
|
-
module Elasticsearch
|
13
|
-
module Persistence
|
14
|
-
|
15
|
-
# When included, extends a plain Ruby class with persistence-related features via the ActiveRecord pattern
|
16
|
-
#
|
17
|
-
# @example Include the repository in a custom class
|
18
|
-
#
|
19
|
-
# require 'elasticsearch/persistence/model'
|
20
|
-
#
|
21
|
-
# class MyObject
|
22
|
-
# include Elasticsearch::Persistence::Repository
|
23
|
-
# end
|
24
|
-
#
|
25
|
-
module Model
|
26
|
-
def self.included(base)
|
27
|
-
base.class_eval do
|
28
|
-
include ActiveModel::Naming
|
29
|
-
include ActiveModel::Conversion
|
30
|
-
include ActiveModel::Serialization
|
31
|
-
include ActiveModel::Serializers::JSON
|
32
|
-
include ActiveModel::Validations
|
33
|
-
|
34
|
-
include Virtus.model
|
35
|
-
|
36
|
-
extend ActiveModel::Callbacks
|
37
|
-
define_model_callbacks :create, :save, :update, :destroy
|
38
|
-
define_model_callbacks :find, :touch, only: :after
|
39
|
-
|
40
|
-
include Elasticsearch::Persistence::Model::Base::InstanceMethods
|
41
|
-
|
42
|
-
extend Elasticsearch::Persistence::Model::Store::ClassMethods
|
43
|
-
include Elasticsearch::Persistence::Model::Store::InstanceMethods
|
44
|
-
|
45
|
-
extend Elasticsearch::Persistence::Model::Find::ClassMethods
|
46
|
-
|
47
|
-
class << self
|
48
|
-
# Re-define the Virtus' `attribute` method, to configure Elasticsearch mapping as well
|
49
|
-
#
|
50
|
-
def attribute(name, type=nil, options={}, &block)
|
51
|
-
mapping = options.delete(:mapping) || {}
|
52
|
-
super
|
53
|
-
|
54
|
-
gateway.mapping do
|
55
|
-
indexes name, {type: Utils::lookup_type(type)}.merge(mapping)
|
56
|
-
end
|
57
|
-
|
58
|
-
gateway.mapping(&block) if block_given?
|
59
|
-
end
|
60
|
-
|
61
|
-
# Return the {Repository::Class} instance
|
62
|
-
#
|
63
|
-
def gateway(&block)
|
64
|
-
@gateway ||= Elasticsearch::Persistence::Repository::Class.new host: self
|
65
|
-
block.arity < 1 ? @gateway.instance_eval(&block) : block.call(@gateway) if block_given?
|
66
|
-
@gateway
|
67
|
-
end
|
68
|
-
|
69
|
-
DEPRECATION_WARNING = "This (ActiveRecord) persistence pattern is deprecated. It will be removed in " +
|
70
|
-
"version 6.0 in favor of the Repository pattern. Please see the ReadMe for " +
|
71
|
-
"details on the alternative pattern.\n" +
|
72
|
-
"https://github.com/elastic/elasticsearch-rails/tree/master/elasticsearch-persistence" +
|
73
|
-
"#the-repository-pattern".freeze
|
74
|
-
|
75
|
-
# Warn that this ActiveRecord persistence pattern is deprecated.
|
76
|
-
#
|
77
|
-
def raise_deprecation_warning!
|
78
|
-
if STDERR.tty?
|
79
|
-
Kernel.warn("\e[31;1m#{DEPRECATION_WARNING}\e[0m")
|
80
|
-
else
|
81
|
-
Kernel.warn(DEPRECATION_WARNING)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
# Delegate methods to repository
|
86
|
-
#
|
87
|
-
delegate :settings,
|
88
|
-
:mappings,
|
89
|
-
:mapping,
|
90
|
-
:document_type=,
|
91
|
-
:index_name,
|
92
|
-
:index_name=,
|
93
|
-
:find,
|
94
|
-
:exists?,
|
95
|
-
:create_index!,
|
96
|
-
:refresh_index!,
|
97
|
-
to: :gateway
|
98
|
-
|
99
|
-
# forward document type to mappings when set
|
100
|
-
def document_type(type = nil)
|
101
|
-
return gateway.document_type unless type
|
102
|
-
gateway.document_type type
|
103
|
-
mapping.type = type
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
# Configure the repository based on the model (set up index_name, etc)
|
108
|
-
#
|
109
|
-
gateway do
|
110
|
-
klass base
|
111
|
-
index_name base.model_name.collection.gsub(/\//, '-')
|
112
|
-
document_type base.model_name.element
|
113
|
-
|
114
|
-
def serialize(document)
|
115
|
-
document.to_hash.except(:id, 'id')
|
116
|
-
end
|
117
|
-
|
118
|
-
def deserialize(document)
|
119
|
-
object = klass.new document['_source']
|
120
|
-
|
121
|
-
# Set the meta attributes when fetching the document from Elasticsearch
|
122
|
-
#
|
123
|
-
object.instance_variable_set :@_id, document['_id']
|
124
|
-
object.instance_variable_set :@_index, document['_index']
|
125
|
-
object.instance_variable_set :@_type, document['_type']
|
126
|
-
object.instance_variable_set :@_version, document['_version']
|
127
|
-
object.instance_variable_set :@_source, document['_source']
|
128
|
-
|
129
|
-
# Store the "hit" information (highlighting, score, ...)
|
130
|
-
#
|
131
|
-
object.instance_variable_set :@hit,
|
132
|
-
Elasticsearch::Model::HashWrapper.new(document.except('_index', '_type', '_id', '_version', '_source'))
|
133
|
-
|
134
|
-
object.instance_variable_set(:@persisted, true)
|
135
|
-
object
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
# Set up common attributes
|
140
|
-
#
|
141
|
-
attribute :created_at, Time, default: lambda { |o,a| Time.now.utc }
|
142
|
-
attribute :updated_at, Time, default: lambda { |o,a| Time.now.utc }
|
143
|
-
|
144
|
-
attr_reader :hit
|
145
|
-
|
146
|
-
raise_deprecation_warning!
|
147
|
-
end
|
148
|
-
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
end
|
153
|
-
end
|
@@ -1,87 +0,0 @@
|
|
1
|
-
module Elasticsearch
|
2
|
-
module Persistence
|
3
|
-
module Model
|
4
|
-
# This module contains the base interface for models
|
5
|
-
#
|
6
|
-
module Base
|
7
|
-
module InstanceMethods
|
8
|
-
|
9
|
-
# Model initializer sets the `@id` variable if passed
|
10
|
-
#
|
11
|
-
def initialize(attributes={})
|
12
|
-
@_id = attributes[:id] || attributes['id']
|
13
|
-
super
|
14
|
-
end
|
15
|
-
|
16
|
-
# Return model attributes as a Hash, merging in the `id`
|
17
|
-
#
|
18
|
-
def attributes
|
19
|
-
super.merge id: id
|
20
|
-
end
|
21
|
-
|
22
|
-
# Return the document `_id`
|
23
|
-
#
|
24
|
-
def id
|
25
|
-
@_id
|
26
|
-
end; alias :_id :id
|
27
|
-
|
28
|
-
# Set the document `_id`
|
29
|
-
#
|
30
|
-
def id=(value)
|
31
|
-
@_id = value
|
32
|
-
end; alias :_id= :id=
|
33
|
-
|
34
|
-
# Return the document `_index`
|
35
|
-
#
|
36
|
-
def _index
|
37
|
-
@_index
|
38
|
-
end
|
39
|
-
|
40
|
-
# Return the document `_type`
|
41
|
-
#
|
42
|
-
def _type
|
43
|
-
@_type
|
44
|
-
end
|
45
|
-
|
46
|
-
# Return the document `_version`
|
47
|
-
#
|
48
|
-
def _version
|
49
|
-
@_version
|
50
|
-
end
|
51
|
-
|
52
|
-
# Return the raw document `_source`
|
53
|
-
#
|
54
|
-
def _source
|
55
|
-
@_source
|
56
|
-
end
|
57
|
-
|
58
|
-
def to_s
|
59
|
-
"#<#{self.class} #{attributes.to_hash.inspect.gsub(/:(\w+)=>/, '\1: ')}>"
|
60
|
-
end; alias :inspect :to_s
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
# Utility methods for {Elasticsearch::Persistence::Model}
|
65
|
-
#
|
66
|
-
module Utils
|
67
|
-
|
68
|
-
# Return Elasticsearch type based on passed Ruby class (used in the `attribute` method)
|
69
|
-
#
|
70
|
-
def lookup_type(type)
|
71
|
-
case
|
72
|
-
when type == String
|
73
|
-
'text'
|
74
|
-
when type == Integer
|
75
|
-
'integer'
|
76
|
-
when type == Float
|
77
|
-
'float'
|
78
|
-
when type == Date || type == Time || type == DateTime
|
79
|
-
'date'
|
80
|
-
when type == Virtus::Attribute::Boolean
|
81
|
-
'boolean'
|
82
|
-
end
|
83
|
-
end; module_function :lookup_type
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|