Module: ErpIntegration::Resources::Persistence::ClassMethods

Defined in:
lib/erp_integration/resources/persistence.rb

Instance Method Summary collapse

Instance Method Details

#bulk_create(attributes_array) ⇒ Array<ErpIntegration::Resource>

Creates many resources in the ERP with a single request.

The underlying adapter call is atomic: a single validation failure rejects the whole batch. On failure, every returned resource is marked invalid with the same shared error message.

Parameters:

  • attributes_array (Array<Hash>)

    Per-record attribute hashes.

Returns:



31
32
33
34
35
36
37
38
39
# File 'lib/erp_integration/resources/persistence.rb', line 31

def bulk_create(attributes_array)
  attrs_list, error_messages = adapter.bulk_create(attributes_array)

  attrs_list.map do |attrs|
    new_resource = new(attrs)
    new_resource.validate_with(error_messages)
    new_resource
  end
end

#create(attributes) ⇒ ErpIntegration::Resource

Creates a new resource in the ERP.

Parameters:

  • attributes (Hash)

    A list of attributes for the new resource.

Returns:



14
15
16
17
18
19
20
# File 'lib/erp_integration/resources/persistence.rb', line 14

def create(attributes)
  attrs, error_messages = adapter.create(**attributes)

  new_resource = new(attrs)
  new_resource.validate_with(error_messages)
  new_resource
end