Module: Castanet::QueryBuilding
- Included in:
- ServiceTicket
- Defined in:
- lib/castanet/query_building.rb
Overview
Contains a method to build query strings.
Instance Method Summary collapse
-
#query(*key_value_pairs) ⇒ Object
Generates query strings.
Instance Method Details
#query(*key_value_pairs) ⇒ Object
Generates query strings.
Given a list of the form
[ [k1, v1],
...
[kn, vn]
]
produces the query string
e(k1)=e(v1)&...&e(kn)=e(vn)
where e
is a function that escapes strings for query strings. The
implementation of e
in this module is the escape
method from
Rack::Utils
.
Key-value pairs that have null values will be removed from the query string.
29 30 31 32 |
# File 'lib/castanet/query_building.rb', line 29 def query(*key_value_pairs) key_value_pairs.reject { |_, v| !v }. map { |x, y| escape(x) + '=' + escape(y) }.join('&') end |