Sha256: 251b7ddbfcfe5b14205283686583e4d00eb1bc0d880b90fbd19dc602ed67d873
Contents?: true
Size: 764 Bytes
Versions: 3
Compression:
Stored size: 764 Bytes
Contents
module SweetParams module Extensions def has?(path, options = nil) options ? !!validate(path, options) : get_param_by_path(path).present? end def validate(path, options) param = get_param_by_path(path) param.present? && allowed?(param, options) ? param : nil end def validate_to_sym(path, options) validate(path, options).try(:to_sym) end private def get_param_by_path(*path) path.flatten.reduce(self) { |hash, key| hash && hash[key] } end def allowed?(param, options) if (whitelist = *options[:in]).any? whitelist.flatten.map(&:to_s).include?(param) else false end end end end ActionController::Parameters.send :include, SweetParams::Extensions
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
sweet_params-0.1.1 | lib/sweet_params/extensions.rb |
sweet_params-0.1.0 | lib/sweet_params/extensions.rb |
sweet_params-0.0.1 | lib/sweet_params/extensions.rb |