Class: Bulk::Collection
- Inherits:
-
AbstractCollection
- Object
- AbstractCollection
- Bulk::Collection
- Defined in:
- lib/bulk/collection.rb
Defined Under Namespace
Instance Method Summary collapse
-
#errors ⇒ Object
Returns errors for the records.
- #to_hash(name, options = {}) ⇒ Object
Methods inherited from AbstractCollection
#clear, #delete, #empty?, #get, #ids, #initialize, #length, #set
Constructor Details
This class inherits a constructor from Bulk::AbstractCollection
Instance Method Details
#errors ⇒ Object
Returns errors for the records
28 29 30 |
# File 'lib/bulk/collection.rb', line 28 def errors @errors ||= Errors.new(self) end |
#to_hash(name, options = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/bulk/collection.rb', line 32 def to_hash(name, = {}) only_ids = [:only_ids] response = {} each do |id, record| next if errors.get(id) response[name] ||= [] response[name] << (only_ids ? record.id : record.as_json([:as_json_options]) ) end errors.each do |id, error| response[:errors] ||= {name => {}} response[:errors][name][id] = error.to_hash end response end |