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.57.0 lib/erp_integration/resources/persistence.rb
erp_integration-0.56.0 lib/erp_integration/resources/persistence.rb
erp_integration-0.55.0 lib/erp_integration/resources/persistence.rb
erp_integration-0.54.0 lib/erp_integration/resources/persistence.rb
erp_integration-0.53.1 lib/erp_integration/resources/persistence.rb
erp_integration-0.53.0 lib/erp_integration/resources/persistence.rb
erp_integration-0.52.0 lib/erp_integration/resources/persistence.rb
erp_integration-0.50.0 lib/erp_integration/resources/persistence.rb
erp_integration-0.49.0 lib/erp_integration/resources/persistence.rb
erp_integration-0.48.0 lib/erp_integration/resources/persistence.rb
erp_integration-0.43.0 lib/erp_integration/resources/persistence.rb
erp_integration-0.42.0 lib/erp_integration/resources/persistence.rb
erp_integration-0.41.0 lib/erp_integration/resources/persistence.rb
erp_integration-0.40.0 lib/erp_integration/resources/persistence.rb
erp_integration-0.39.0 lib/erp_integration/resources/persistence.rb
erp_integration-0.38.0 lib/erp_integration/resources/persistence.rb
erp_integration-0.37.0 lib/erp_integration/resources/persistence.rb
erp_integration-0.36.1 lib/erp_integration/resources/persistence.rb
erp_integration-0.36.0 lib/erp_integration/resources/persistence.rb
erp_integration-0.35.0 lib/erp_integration/resources/persistence.rb