Module: ModelExtensions::Order::Validations

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object


7
8
9
10
11
12
# File 'app/api/model_extensions/order.rb', line 7

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.


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

def include_unset_values?
  not building?
end

#request_options_for_validationObject


32
33
34
# File 'app/api/model_extensions/order.rb', line 32

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

#request_types_delegate_validatorObject


22
23
24
# File 'app/api/model_extensions/order.rb', line 22

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