Class: Wayfarer::Routing::Matchers::Query
- Inherits:
-
Struct
- Object
- Struct
- Wayfarer::Routing::Matchers::Query
- Defined in:
- lib/wayfarer/routing/matchers/query.rb
Instance Attribute Summary collapse
-
#fields ⇒ Object
Returns the value of attribute fields.
Instance Method Summary collapse
Instance Attribute Details
#fields ⇒ Object
Returns the value of attribute fields
6 7 8 |
# File 'lib/wayfarer/routing/matchers/query.rb', line 6 def fields @fields end |
Instance Method Details
#match(url) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/wayfarer/routing/matchers/query.rb', line 7 def match(url) query = url.query # CGI::parse throws a NoMethodError if the query is an empty string return false if query.nil? || query.empty? CGI.parse(query).none? { |field, vals| violates?(field, vals) } end |
#params(url) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/wayfarer/routing/matchers/query.rb', line 16 def params(url) return {} unless match(url) CGI.parse(url.query) .select { |(k, _)| fields.keys.include?(k.to_sym) } .transform_values(&:last) end |