class PetfinderV2::Services::OptionsValidator

Constants

BASE_OPTS_MAP

Public Class Methods

new(opts) click to toggle source
# File lib/petfinder_V2/services/options_validator.rb, line 13
def initialize(opts)
  @opts = opts
end

Public Instance Methods

my_opts() click to toggle source
# File lib/petfinder_V2/services/options_validator.rb, line 17
def my_opts
  raise 'Abstract Method - Only call in subclasses'
end
run() click to toggle source
# File lib/petfinder_V2/services/options_validator.rb, line 21
def run
  errors = []
  my_opts_map = BASE_OPTS_MAP.merge(my_opts)
  @opts.each do |key, val|
    key = key.to_sym
    if my_opts_map[key].nil?
      errors << "#{key} is not a valid option"
      next
    end
    pf_opt = my_opts_map[key]
    errors << pf_opt.validate_value(val, key)
  end
  errors.flatten.compact
end