|
1 | 1 | require 'hashie/mash' |
2 | 2 |
|
3 | 3 | require 'elasticsearch' |
4 | | - |
5 | | -require 'elasticsearch/model/hash_wrapper' |
6 | | -require 'elasticsearch/model/indexing' |
7 | | -require 'elasticsearch/model/searching' |
8 | | - |
9 | | -require 'active_support/inflector' |
| 4 | +require 'elasticsearch/model' |
10 | 5 |
|
11 | 6 | require 'elasticsearch/persistence/version' |
12 | | - |
13 | | -require 'elasticsearch/persistence/client' |
14 | | -require 'elasticsearch/persistence/repository/response/results' |
15 | | -require 'elasticsearch/persistence/repository/naming' |
16 | | -require 'elasticsearch/persistence/repository/serialize' |
17 | | -require 'elasticsearch/persistence/repository/store' |
18 | | -require 'elasticsearch/persistence/repository/find' |
19 | | -require 'elasticsearch/persistence/repository/search' |
20 | | -require 'elasticsearch/persistence/repository/class' |
21 | 7 | require 'elasticsearch/persistence/repository' |
22 | | - |
23 | | -module Elasticsearch |
24 | | - |
25 | | - # Persistence for Ruby domain objects and models in Elasticsearch |
26 | | - # =============================================================== |
27 | | - # |
28 | | - # `Elasticsearch::Persistence` contains modules for storing and retrieving Ruby domain objects and models |
29 | | - # in Elasticsearch. |
30 | | - # |
31 | | - # == Repository |
32 | | - # |
33 | | - # The repository patterns allows to store and retrieve Ruby objects in Elasticsearch. |
34 | | - # |
35 | | - # require 'elasticsearch/persistence' |
36 | | - # |
37 | | - # class Note |
38 | | - # def to_hash; {foo: 'bar'}; end |
39 | | - # end |
40 | | - # |
41 | | - # repository = Elasticsearch::Persistence::Repository.new |
42 | | - # |
43 | | - # repository.save Note.new |
44 | | - # # => {"_index"=>"repository", "_type"=>"note", "_id"=>"mY108X9mSHajxIy2rzH2CA", ...} |
45 | | - # |
46 | | - # Customize your repository by including the main module in a Ruby class |
47 | | - # class MyRepository |
48 | | - # include Elasticsearch::Persistence::Repository |
49 | | - # |
50 | | - # index 'my_notes' |
51 | | - # klass Note |
52 | | - # |
53 | | - # client Elasticsearch::Client.new log: true |
54 | | - # end |
55 | | - # |
56 | | - # repository = MyRepository.new |
57 | | - # |
58 | | - # repository.save Note.new |
59 | | - # # 2014-04-04 22:15:25 +0200: POST http://localhost:9200/my_notes/note [status:201, request:0.009s, query:n/a] |
60 | | - # # 2014-04-04 22:15:25 +0200: > {"foo":"bar"} |
61 | | - # # 2014-04-04 22:15:25 +0200: < {"_index":"my_notes","_type":"note","_id":"-d28yXLFSlusnTxb13WIZQ", ...} |
62 | | - # |
63 | | - # == Model |
64 | | - # |
65 | | - # The active record pattern allows to use the interface familiar from ActiveRecord models: |
66 | | - # |
67 | | - # require 'elasticsearch/persistence' |
68 | | - # |
69 | | - # class Article |
70 | | - # attribute :title, String, mapping: { analyzer: 'snowball' } |
71 | | - # end |
72 | | - # |
73 | | - # article = Article.new id: 1, title: 'Test' |
74 | | - # article.save |
75 | | - # |
76 | | - # Article.find(1) |
77 | | - # |
78 | | - # article.update_attributes title: 'Update' |
79 | | - # |
80 | | - # article.destroy |
81 | | - # |
82 | | - module Persistence |
83 | | - |
84 | | - # :nodoc: |
85 | | - module ClassMethods |
86 | | - |
87 | | - # Get or set the default client for all repositories and models |
88 | | - # |
89 | | - # @example Set and configure the default client |
90 | | - # |
91 | | - # Elasticsearch::Persistence.client Elasticsearch::Client.new host: 'http://localhost:9200', tracer: true |
92 | | - # |
93 | | - # @example Perform an API request through the client |
94 | | - # |
95 | | - # Elasticsearch::Persistence.client.cluster.health |
96 | | - # # => { "cluster_name" => "elasticsearch" ... } |
97 | | - # |
98 | | - def client client=nil |
99 | | - @client = client || @client || Elasticsearch::Client.new |
100 | | - end |
101 | | - |
102 | | - # Set the default client for all repositories and models |
103 | | - # |
104 | | - # @example Set and configure the default client |
105 | | - # |
106 | | - # Elasticsearch::Persistence.client = Elasticsearch::Client.new host: 'http://localhost:9200', tracer: true |
107 | | - # => #<Elasticsearch::Transport::Client:0x007f96a6dd0d80 @transport=... > |
108 | | - # |
109 | | - def client=(client) |
110 | | - @client = client |
111 | | - end |
112 | | - end |
113 | | - |
114 | | - extend ClassMethods |
115 | | - end |
116 | | -end |
| 8 | +require 'elasticsearch/persistence/repository/response/results' |
0 commit comments