module SweetParams::Extensions
Public Instance Methods
has?(path, options = nil)
click to toggle source
# File lib/sweet_params/extensions.rb, line 3 def has?(path, options = nil) options ? !!validate(path, options) : get_param_by_path(path).present? end
validate(path, options)
click to toggle source
# File lib/sweet_params/extensions.rb, line 7 def validate(path, options) param = get_param_by_path(path) param.present? && allowed?(param, options) ? param : nil end
validate_to_sym(path, options)
click to toggle source
# File lib/sweet_params/extensions.rb, line 12 def validate_to_sym(path, options) validate(path, options).try(:to_sym) end
Private Instance Methods
allowed?(param, options)
click to toggle source
# File lib/sweet_params/extensions.rb, line 22 def allowed?(param, options) if (whitelist = *options[:in]).any? whitelist.flatten.map(&:to_s).include?(param) else false end end
get_param_by_path(*path)
click to toggle source
# File lib/sweet_params/extensions.rb, line 18 def get_param_by_path(*path) path.flatten.reduce(self) { |hash, key| hash && hash[key] } end