Class: ElasticRecord::SearchesMany::CollectionProxy

Inherits:
Relation
  • Object
show all
Defined in:
lib/elastic_record/searches_many/collection_proxy.rb

Constant Summary

Constants inherited from Relation

Relation::MULTI_VALUE_METHODS, Relation::SINGLE_VALUE_METHODS

Instance Attribute Summary

Attributes inherited from Relation

#klass, #values

Instance Method Summary collapse

Methods inherited from Relation

#==, #count, #eager_loading?, #explain, #facets, #initialize_copy, #inspect, #scoping, #to_ids

Methods included from Relation::Admin

#create_percolator, #create_warmer

Methods included from Relation::Batches

#find_each, #find_ids_in_batches, #find_in_batches, #reindex

Methods included from Relation::Delegation

#include?, #to_ary

Methods included from Relation::FinderMethods

#all, #find, #first, #first!, #last

Methods included from Relation::Merging

#merge, #merge!

Methods included from Relation::SearchMethods

#as_elastic, #eager_load, #eager_load!, #extending, #extending!, #facet, #facet!, #filter, #filter!, #find_by, #find_by!, #limit, #limit!, #none, #offset, #offset!, #order, #order!, #query, #query!, #reverse_order, #reverse_order!, #select, #select!

Constructor Details

#initialize(association) ⇒ CollectionProxy

Returns a new instance of CollectionProxy.



4
5
6
7
8
# File 'lib/elastic_record/searches_many/collection_proxy.rb', line 4

def initialize(association)
  @association = association
  super association.klass
  merge! association.scope
end

Dynamic Method Handling

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

Instance Method Details

#<<(*records) ⇒ Object Also known as: push



20
21
22
# File 'lib/elastic_record/searches_many/collection_proxy.rb', line 20

def <<(*records)
  @association.concat(records) && self
end

#eager_loaded(records) ⇒ Object



10
11
12
# File 'lib/elastic_record/searches_many/collection_proxy.rb', line 10

def eager_loaded(records)
  @association.eager_loaded_collection(records)
end

#to_aObject



14
15
16
17
18
# File 'lib/elastic_record/searches_many/collection_proxy.rb', line 14

def to_a
  records = @association.load_collection.reject(&:destroyed?)
  records = eager_load_associations(records) if eager_loading?
  records
end