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

Version Path
erp_integration-0.34.0 lib/erp_integration/resources/persistence.rb
erp_integration-0.33.0 lib/erp_integration/resources/persistence.rb
erp_integration-0.32.0 lib/erp_integration/resources/persistence.rb
erp_integration-0.31.0 lib/erp_integration/resources/persistence.rb
erp_integration-0.30.0 lib/erp_integration/resources/persistence.rb
erp_integration-0.29.0 lib/erp_integration/resources/persistence.rb
erp_integration-0.28.1 lib/erp_integration/resources/persistence.rb
erp_integration-0.28.0 lib/erp_integration/resources/persistence.rb
erp_integration-0.27.0 lib/erp_integration/resources/persistence.rb
erp_integration-0.26.0 lib/erp_integration/resources/persistence.rb
erp_integration-0.25.0 lib/erp_integration/resources/persistence.rb
erp_integration-0.24.0 lib/erp_integration/resources/persistence.rb
erp_integration-0.23.0 lib/erp_integration/resources/persistence.rb
erp_integration-0.22.0 lib/erp_integration/resources/persistence.rb
erp_integration-0.21.0 lib/erp_integration/resources/persistence.rb
erp_integration-0.20.0 lib/erp_integration/resources/persistence.rb
erp_integration-0.19.0 lib/erp_integration/resources/persistence.rb
erp_integration-0.18.0 lib/erp_integration/resources/persistence.rb
erp_integration-0.17.0 lib/erp_integration/resources/persistence.rb
erp_integration-0.16.0 lib/erp_integration/resources/persistence.rb