Class: Bulk::Collection

Inherits:
AbstractCollection show all
Defined in:
lib/bulk/collection.rb

Defined Under Namespace

Classes: Error, Errors

Instance Method Summary collapse

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

#errorsObject

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, options = {})
  only_ids = options[:only_ids]
  response = {}

  each do |id, record|
    next if errors.get(id)
    response[name] ||= []
    response[name] << (only_ids ? record.id : record.as_json(options[:as_json_options]) )
  end

  errors.each do |id, error|
    response[:errors] ||= {name => {}}
    response[:errors][name][id] = error.to_hash
  end

  response
end