Module: ErpIntegration::Resources::Persistence::ClassMethods
- Defined in:
- lib/erp_integration/resources/persistence.rb
Instance Method Summary collapse
-
#bulk_create(attributes_array) ⇒ Array<ErpIntegration::Resource>
Creates many resources in the ERP with a single request.
-
#create(attributes) ⇒ ErpIntegration::Resource
Creates a new resource in the ERP.
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.
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, = adapter.bulk_create(attributes_array) attrs_list.map do |attrs| new_resource = new(attrs) new_resource.validate_with() new_resource end end |
#create(attributes) ⇒ ErpIntegration::Resource
Creates a new resource in the ERP.
14 15 16 17 18 19 20 |
# File 'lib/erp_integration/resources/persistence.rb', line 14 def create(attributes) attrs, = adapter.create(**attributes) new_resource = new(attrs) new_resource.validate_with() new_resource end |