Module: ModelExtensions::Order::Validations

Defined in:
app/api/model_extensions/order.rb

Overview

rubocop:todo Style/Documentation

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object


10
11
12
13
14
15
16
17
18
# File 'app/api/model_extensions/order.rb', line 10

def self.included(base)
  base.class_eval do
    extend DelegateValidation
    delegate_validation :request_options_for_validation,
                        as: 'request_options',
                        to: :request_types,
                        if: :validate_request_options?
  end
end

Instance Method Details

#include_unset_values?Boolean

If this returns true then we check values that have not been set, otherwise we can ignore them. This would mean that we should not require values that are unset, until we're moving out of the building state.

Returns:

  • (Boolean)

36
37
38
# File 'app/api/model_extensions/order.rb', line 36

def include_unset_values?
  not building?
end

#request_options_for_validationObject


40
41
42
# File 'app/api/model_extensions/order.rb', line 40

def request_options_for_validation
  RequestOptionForValidation.new({ owner: self }.reverse_merge(request_options || {}))
end

#request_types_delegate_validatorObject


28
29
30
31
32
# File 'app/api/model_extensions/order.rb', line 28

def request_types_delegate_validator
  DelegateValidation::CompositeValidator.construct(
    *::RequestType.find(request_types.flatten).map(&:delegate_validator)
  )
end