forked from elastic/elasticsearch-rails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.rb
71 lines (65 loc) · 2.21 KB
/
class.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
module Elasticsearch
module Persistence
module Repository
# The default repository class, to be used either directly, or as a gateway in a custom repository class
#
# @example Standalone use
#
# repository = Elasticsearch::Persistence::Repository::Class.new
# # => #<Elasticsearch::Persistence::Repository::Class ...>
# repository.save(my_object)
# # => {"_index"=> ... }
#
# @example Shortcut use
#
# repository = Elasticsearch::Persistence::Repository.new
# # => #<Elasticsearch::Persistence::Repository::Class ...>
#
# @example Configuration via a block
#
# repository = Elasticsearch::Persistence::Repository.new do
# index 'my_notes'
# end
#
# # => #<Elasticsearch::Persistence::Repository::Class ...>
# # > repository.save(my_object)
# # => {"_index"=> ... }
#
# @example Accessing the gateway in a custom class
#
# class MyRepository
# include Elasticsearch::Persistence::Repository
# end
#
# repository = MyRepository.new
#
# repository.gateway.client.info
# # => {"status"=>200, "name"=>"Venom", ... }
#
class Class
include Elasticsearch::Persistence::Repository::Client
include Elasticsearch::Persistence::Repository::Naming
include Elasticsearch::Persistence::Repository::Serialize
include Elasticsearch::Persistence::Repository::Store
include Elasticsearch::Persistence::Repository::Find
include Elasticsearch::Persistence::Repository::Search
include Elasticsearch::Model::Indexing::ClassMethods
attr_reader :options
def initialize(options={}, &block)
@options = options
index_name options.delete(:index)
block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
end
# Return the "host" class, if this repository is a gateway hosted in another class
#
# @return [nil, Class]
#
# @api private
#
def host
options[:host]
end
end
end
end
end