Class: FriendlyRoutes::Params::HashParams
- Defined in:
- lib/friendly_routes/params/hash_params.rb
Instance Attribute Summary collapse
-
#hash ⇒ Hash
keys are values for matching and values is needed values.
Attributes inherited from Base
Instance Method Summary collapse
-
#allowed?(value) ⇒ Boolean
Check if value can be composed.
-
#compose(value) ⇒ String, Symbol
Generate request value from params.
- #constraints ⇒ Object
-
#initialize(name, hash, optional: true) ⇒ HashParams
constructor
A new instance of HashParams.
-
#parse(value) ⇒ Object
Parse values from request.
Methods inherited from Base
Constructor Details
#initialize(name, hash, optional: true) ⇒ HashParams
Returns a new instance of HashParams.
9 10 11 12 13 |
# File 'lib/friendly_routes/params/hash_params.rb', line 9 def initialize(name, hash, optional: true) super(:collection, name, optional) @hash = hash check_params end |
Instance Attribute Details
#hash ⇒ Hash
keys are values for matching and values is needed values
6 7 8 |
# File 'lib/friendly_routes/params/hash_params.rb', line 6 def hash @hash end |
Instance Method Details
#allowed?(value) ⇒ Boolean
Check if value can be composed
36 37 38 |
# File 'lib/friendly_routes/params/hash_params.rb', line 36 def allowed?(value) @hash.values.include?(value) end |
#compose(value) ⇒ String, Symbol
Generate request value from params
Inverse of #parse
29 30 31 |
# File 'lib/friendly_routes/params/hash_params.rb', line 29 def compose(value) @hash.key(value) end |
#constraints ⇒ Object
15 16 17 |
# File 'lib/friendly_routes/params/hash_params.rb', line 15 def constraints Regexp.new @hash.keys.join('|') end |
#parse(value) ⇒ Object
Parse values from request
Inverse of #compose
22 23 24 |
# File 'lib/friendly_routes/params/hash_params.rb', line 22 def parse(value) @hash[value] end |