Sha256: ed8f4df00e0d72b270ecd51f083d94c9ba6c498aac1349a5ca46b0887d77e6e9
Contents?: true
Size: 1.17 KB
Versions: 4
Compression:
Stored size: 1.17 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 end end end
Version data entries
4 entries across 4 versions & 1 rubygems