Class: Ghtk::Validations::OrderValidation

Inherits:
Object
  • Object
show all
Defined in:
lib/ghtk/validations/order_validation.rb

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ OrderValidation

Returns a new instance of OrderValidation.



4
5
6
# File 'lib/ghtk/validations/order_validation.rb', line 4

def initialize(hash)
  @hash = hash
end

Instance Method Details

#validate!Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ghtk/validations/order_validation.rb', line 8

def validate!
  blank_params = []
  REQUIRED_PARAMS.each do |key, sub_keys|
    sub_keys.each do |sub_key|
      blank_params << "#{key}.#{sub_key}" if Ghtk.is_blank?(hash.dig(key, sub_key))
    end
  end
  unless hash.dig(:order, :use_return_address).to_i.zero?
    REQUIRED_RETURN_PARAMS.each do |key, sub_keys|
      sub_keys.each do |sub_key|
        blank_params << "#{key}.#{sub_key}" if Ghtk.is_blank?(hash.dig(key, sub_key))
      end
    end
  end
  raise Ghtk::BadParamsError.new("Params: #{blank_params.join(', ')} is blank!") unless blank_params.empty?
  return true
end