Class: RemoteRecord::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/remote_record/collection.rb

Overview

Wraps operations on collections of remote references. By calling #remote on on an ActiveRecord relation, you’ll get a RemoteRecord::Collection you can use to more easily fetch multiple records at once.

The default implementation is naive and sends a request per object.

Instance Method Summary collapse

Constructor Details

#initialize(active_record_relation, config = nil, id: :remote_resource_id) ⇒ Collection



12
13
14
15
16
# File 'lib/remote_record/collection.rb', line 12

def initialize(active_record_relation, config = nil, id: :remote_resource_id)
  @relation = active_record_relation
  @config = config
  @id_field = id
end

Instance Method Details

#allObject



18
19
20
# File 'lib/remote_record/collection.rb', line 18

def all
  fetch_all_scoped_records(@relation)
end

#whereObject

Raises:

  • (NotImplementedError.new)


22
23
24
25
# File 'lib/remote_record/collection.rb', line 22

def where
  raise NotImplementedError.new,
        "Implement #where on #{self.class.name} to filter records using the API."
end