class FriendlyRoutes::Params::HashParams
@attr [Hash] hash keys are values for matching and values is needed values
Attributes
hash[RW]
Public Class Methods
new(name, hash, optional: true)
click to toggle source
Calls superclass method
FriendlyRoutes::Params::Base::new
# File lib/friendly_routes/params/hash_params.rb, line 9 def initialize(name, hash, optional: true) super(:collection, name, optional) @hash = hash check_params @hash = @hash.map do |k, v| [k, v.try(:to_s) || v] end.to_h end
Public Instance Methods
allowed?(value)
click to toggle source
(see Base#allowed?
) @param [Object] value hash value @return [Boolean]
# File lib/friendly_routes/params/hash_params.rb, line 39 def allowed?(value) @hash.values.include?(value) || @hash.values.include?(value.try(:to_s)) end
compose(value)
click to toggle source
(see Base#compose
) @param [Object] value hash value @return [String, Symbol] hash key
# File lib/friendly_routes/params/hash_params.rb, line 32 def compose(value) @hash.key(value) || @hash.key(value.try(:to_s)) end
constraints()
click to toggle source
# File lib/friendly_routes/params/hash_params.rb, line 18 def constraints Regexp.new @hash.keys.join('|') end
parse(value)
click to toggle source
(see Base#parse
) @param [String, Symbol] value hash key @return [Object] hash value
# File lib/friendly_routes/params/hash_params.rb, line 25 def parse(value) @hash[value] end
Private Instance Methods
check_params()
click to toggle source
# File lib/friendly_routes/params/hash_params.rb, line 45 def check_params raise ArgumentError, 'Invalid hash passed' unless @hash.is_a?(Hash) end