Sha256: 23966d3a2612b9358418e95bab13d0372fd85f05309d75f63e18c67f2597e7fb
Contents?: true
Size: 1.45 KB
Versions: 44
Compression:
Stored size: 1.45 KB
Contents
# frozen_string_literal: true module ErpIntegration module Resources module Persistence def self.included(base) base.extend ClassMethods end module ClassMethods # Creates a new resource in the ERP. # @param attributes [Hash] A list of attributes for the new resource. # @return [ErpIntegration::Resource] The (to be) created resource. def create(attributes) attrs, error_messages = adapter.create(**attributes) new_resource = new(attrs) new_resource.validate_with(error_messages) new_resource end end # Determines whether a `ErpIntegration::Resource` is considered to be persisted. # @return [Boolean] Whether it's persisted or not. def persisted? !id.nil? end # Update an resource in the ERP. # @param attributes [Hash] A list of attributes to update. # @return [Boolean] Whether the update action was succcesful or not. def update(attributes) attrs, error_messages = self.class.adapter.update(id, **attributes) assign_attributes(attrs) validate_with(error_messages) end # Destroy an resource in the ERP. # @return [Boolean] Whether the destroy action was succcesful or not. def destroy(id) attrs, error_messages = self.class.adapter.destroy(id) assign_attributes(attrs) validate_with(error_messages) end end end end
Version data entries
44 entries across 44 versions & 1 rubygems