Class: PetfinderV2::Services::OptionsValidator
- Inherits:
-
Object
- Object
- PetfinderV2::Services::OptionsValidator
show all
- Defined in:
- lib/petfinder_V2/services/options_validator.rb
Constant Summary
collapse
- BASE_OPTS_MAP =
{
name: Option.new(String),
distance: Option.new(Integer),
location: Option.new(String),
page: Option.new(Integer),
sort: Option.new(String)
}.freeze
Instance Method Summary
collapse
Constructor Details
12
13
14
|
# File 'lib/petfinder_V2/services/options_validator.rb', line 12
def initialize(opts)
@opts = opts
end
|
Instance Method Details
#my_opts ⇒ Object
16
17
18
|
# File 'lib/petfinder_V2/services/options_validator.rb', line 16
def my_opts
raise 'Abstract Method - Only call in subclasses'
end
|
#run ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/petfinder_V2/services/options_validator.rb', line 20
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
|