Module: ErpIntegration::Resources::Persistence

Included in:
ErpIntegration::Resource
Defined in:
lib/erp_integration/resources/persistence.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



6
7
8
# File 'lib/erp_integration/resources/persistence.rb', line 6

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#destroy(id) ⇒ Boolean

Destroy an resource in the ERP.

Returns:

  • (Boolean)

    Whether the destroy action was succcesful or not.



41
42
43
44
45
46
# File 'lib/erp_integration/resources/persistence.rb', line 41

def destroy(id)
  attrs, error_messages = self.class.adapter.destroy(id)

  assign_attributes(attrs)
  validate_with(error_messages)
end

#persisted?Boolean

Determines whether a ‘ErpIntegration::Resource` is considered to be persisted.

Returns:

  • (Boolean)

    Whether it’s persisted or not.



25
26
27
# File 'lib/erp_integration/resources/persistence.rb', line 25

def persisted?
  !id.nil?
end

#update(attributes) ⇒ Boolean

Update an resource in the ERP.

Parameters:

  • attributes (Hash)

    A list of attributes to update.

Returns:

  • (Boolean)

    Whether the update action was succcesful or not.



32
33
34
35
36
37
# File 'lib/erp_integration/resources/persistence.rb', line 32

def update(attributes)
  attrs, error_messages = self.class.adapter.update(id, **attributes)

  assign_attributes(attrs)
  validate_with(error_messages)
end