Class: Elasticsearch::Resources::DocumentFactory
- Inherits:
-
Object
- Object
- Elasticsearch::Resources::DocumentFactory
- Defined in:
- lib/elasticsearch/resources/document_factory.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#resources ⇒ Object
readonly
Returns the value of attribute resources.
Instance Method Summary collapse
- #build ⇒ Object
- #build_cluster ⇒ Object
- #build_index ⇒ Object
- #build_type ⇒ Object
- #get_cluster ⇒ Object
- #get_index ⇒ Object
- #get_type ⇒ Object
-
#initialize(content:, resources: {}) ⇒ DocumentFactory
constructor
A new instance of DocumentFactory.
Constructor Details
#initialize(content:, resources: {}) ⇒ DocumentFactory
Returns a new instance of DocumentFactory.
6 7 8 9 |
# File 'lib/elasticsearch/resources/document_factory.rb', line 6 def initialize(content:, resources: {}) @content = content @resources = resources end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
4 5 6 |
# File 'lib/elasticsearch/resources/document_factory.rb', line 4 def content @content end |
#resources ⇒ Object (readonly)
Returns the value of attribute resources.
4 5 6 |
# File 'lib/elasticsearch/resources/document_factory.rb', line 4 def resources @resources end |
Instance Method Details
#build ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/elasticsearch/resources/document_factory.rb', line 11 def build type = get_type type.document_class.new( type: type, id: content['_id'], attributes: content['_source'] ) end |
#build_cluster ⇒ Object
44 45 46 |
# File 'lib/elasticsearch/resources/document_factory.rb', line 44 def build_cluster Elasticsearch::Resources::Cluster.new end |
#build_index ⇒ Object
34 35 36 37 38 |
# File 'lib/elasticsearch/resources/document_factory.rb', line 34 def build_index Elasticsearch::Resources::Index.new(cluster: get_cluster) do |index| index.name = content['_index'] end end |
#build_type ⇒ Object
24 25 26 27 28 |
# File 'lib/elasticsearch/resources/document_factory.rb', line 24 def build_type Elasticsearch::Resources::Type.new(index: get_index) do |type| type.name = content['_type'] end end |
#get_cluster ⇒ Object
40 41 42 |
# File 'lib/elasticsearch/resources/document_factory.rb', line 40 def get_cluster resources[:cluster] || build_cluster end |
#get_index ⇒ Object
30 31 32 |
# File 'lib/elasticsearch/resources/document_factory.rb', line 30 def get_index resources[:index] || build_index end |
#get_type ⇒ Object
20 21 22 |
# File 'lib/elasticsearch/resources/document_factory.rb', line 20 def get_type resources[:type] || build_type end |