class Elasticsearch::Resources::DocumentFactory

Attributes

content[R]
resources[R]

Public Class Methods

new(content:, resources: {}) click to toggle source
# File lib/elasticsearch/resources/document_factory.rb, line 6
def initialize(content:, resources: {})
  @content = content
  @resources = resources
end

Public Instance Methods

build() click to toggle source
# 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() click to toggle source
# File lib/elasticsearch/resources/document_factory.rb, line 44
def build_cluster
  Elasticsearch::Resources::Cluster.new
end
build_index() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/elasticsearch/resources/document_factory.rb, line 40
def get_cluster
  resources[:cluster] || build_cluster
end
get_index() click to toggle source
# File lib/elasticsearch/resources/document_factory.rb, line 30
def get_index
  resources[:index] || build_index
end
get_type() click to toggle source
# File lib/elasticsearch/resources/document_factory.rb, line 20
def get_type
  resources[:type] || build_type
end