Class: MojitoImport::Report
- Inherits:
-
Object
- Object
- MojitoImport::Report
- Defined in:
- lib/mojito_import/report.rb
Instance Attribute Summary collapse
-
#import_id ⇒ Object
Returns the value of attribute import_id.
-
#object_errors ⇒ Object
Returns the value of attribute object_errors.
-
#object_updates ⇒ Object
Returns the value of attribute object_updates.
-
#request_errors ⇒ Object
Returns the value of attribute request_errors.
Instance Method Summary collapse
- #add_object_error(mojito_id, error, field: nil) ⇒ Object
- #add_object_update(mojito_id, field, from, to: nil) ⇒ Object
- #add_request_error(error) ⇒ Object
- #find_errors_for_object(mojito_id) ⇒ Object
-
#initialize(import_id) ⇒ Report
constructor
A new instance of Report.
- #to_json ⇒ Object
Constructor Details
#initialize(import_id) ⇒ Report
7 8 9 10 11 12 |
# File 'lib/mojito_import/report.rb', line 7 def initialize(import_id) self.import_id = import_id self.object_errors = [] self.request_errors = [] self.object_updates = [] end |
Instance Attribute Details
#import_id ⇒ Object
Returns the value of attribute import_id.
5 6 7 |
# File 'lib/mojito_import/report.rb', line 5 def import_id @import_id end |
#object_errors ⇒ Object
Returns the value of attribute object_errors.
5 6 7 |
# File 'lib/mojito_import/report.rb', line 5 def object_errors @object_errors end |
#object_updates ⇒ Object
Returns the value of attribute object_updates.
5 6 7 |
# File 'lib/mojito_import/report.rb', line 5 def object_updates @object_updates end |
#request_errors ⇒ Object
Returns the value of attribute request_errors.
5 6 7 |
# File 'lib/mojito_import/report.rb', line 5 def request_errors @request_errors end |
Instance Method Details
#add_object_error(mojito_id, error, field: nil) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/mojito_import/report.rb', line 43 def add_object_error(mojito_id, error, field: nil) hash_element = object_errors.detect { |error_hash| error_hash["mojitoObjectId"] == mojito_id } if hash_element.nil? hash_element = { "mojitoObjectId" => mojito_id, "general" => [], "fields" => { } } object_errors << hash_element end if field.nil? # it's a general error hash_element["general"] << error else # The field has to be initialized to an array # Else we got an error when adding an error to a 2nd field hash_element["fields"][field] ||= [] hash_element["fields"][field] << error end end |
#add_object_update(mojito_id, field, from, to: nil) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/mojito_import/report.rb', line 27 def add_object_update(mojito_id, field, from, to: nil) hash_element = object_updates.detect { |error_hash| error_hash["mojitoObjectId"] == mojito_id } update_hash = {"before" => from} update_hash["after"] = to unless to.nil? if hash_element.nil? new_update_hash = { "mojitoObjectId" => mojito_id, field => update_hash } object_updates << new_update_hash else hash_element[field] = update_hash end end |
#add_request_error(error) ⇒ Object
23 24 25 |
# File 'lib/mojito_import/report.rb', line 23 def add_request_error(error) request_errors << error end |
#find_errors_for_object(mojito_id) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/mojito_import/report.rb', line 63 def find_errors_for_object(mojito_id) object_error = object_errors.detect { |data| data["mojitoObjectId"] == mojito_id } return if object_error.nil? object_error.except("mojitoObjectId") end |
#to_json ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/mojito_import/report.rb', line 14 def to_json { "mojitoRequestId" => self.import_id, "requestErrors" => self.request_errors, "objectErrors" => self.object_errors, "objectUpdates" => self.object_updates }.to_json end |