Module: ErpIntegration::Resources::Validations

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

Instance Method Summary collapse

Instance Method Details

#errorsErpIntegration::Resources::Errors

Exposes all errors related to an ‘ErpIntegration::Resource`.

Returns:



9
10
11
# File 'lib/erp_integration/resources/validations.rb', line 9

def errors
  @errors ||= Resources::Errors.new
end

#valid?Boolean

Checks whether an resource is considered valid or not.

Returns:

  • (Boolean)

    Is the resource valid according to the ERP?



16
17
18
# File 'lib/erp_integration/resources/validations.rb', line 16

def valid?
  errors.none?
end

#validate_with(*error_messages) ⇒ Boolean

Validates the resource by checking the given error messages.

Parameters:

  • error_messages (Array)

    A list of error messages.

Returns:

  • (Boolean)

    Whether the resource is valid or not.



24
25
26
27
28
29
30
31
32
# File 'lib/erp_integration/resources/validations.rb', line 24

def validate_with(*error_messages)
  errors.clear

  error_messages.flatten.compact.each do |error_message|
    errors.add(error_message)
  end

  valid?
end