Class: ElasticWeb::RelationCollection

Inherits:
Relation
  • Object
show all
Includes:
Enumerable
Defined in:
lib/elasticweb/relation_collection.rb

Instance Attribute Summary collapse

Attributes inherited from Relation

#data

Instance Method Summary collapse

Methods inherited from Relation

#method_missing

Constructor Details

#initialize(data, options = {}) ⇒ RelationCollection

Returns a new instance of RelationCollection.



7
8
9
10
11
12
13
14
15
# File 'lib/elasticweb/relation_collection.rb', line 7

def initialize(data, options = {})
  data = [] unless data.is_a?(Array)

  @collection = Array(data).map do |item|
    Relation.new(item)
  end

  @options = options.with_indifferent_access
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ElasticWeb::Relation

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



5
6
7
# File 'lib/elasticweb/relation_collection.rb', line 5

def collection
  @collection
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/elasticweb/relation_collection.rb', line 5

def options
  @options
end

Instance Method Details

#eachObject



17
18
19
20
21
# File 'lib/elasticweb/relation_collection.rb', line 17

def each
  return enum_for(:each) unless block_given?

  @collection.each { |item| yield item }
end