Module: Rack::Reducer::Parser
- Defined in:
- lib/rack/reducer/parser.rb
Overview
convert params from Sinatra, Rails, Roda, etc into a symbol hash
Class Method Summary collapse
- .call(data) ⇒ Object
-
.hashify(data) ⇒ Object
turns out a Rails params hash is not really a hash it’s safe to call .to_unsafe_hash here, because params are automatically sanitized by the lambda keywords.
- .symbolize(data) ⇒ Object
Class Method Details
.call(data) ⇒ Object
5 6 7 |
# File 'lib/rack/reducer/parser.rb', line 5 def self.call(data) data.is_a?(Hash) ? symbolize(data) : hashify(data) end |
.hashify(data) ⇒ Object
turns out a Rails params hash is not really a hash it’s safe to call .to_unsafe_hash here, because params are automatically sanitized by the lambda keywords
18 19 20 21 |
# File 'lib/rack/reducer/parser.rb', line 18 def self.hashify(data) fn = i[to_unsafe_h to_h].find { |name| data.respond_to?(name) } symbolize(data.send(fn)) end |
.symbolize(data) ⇒ Object
9 10 11 12 13 |
# File 'lib/rack/reducer/parser.rb', line 9 def self.symbolize(data) data.each_with_object({}) do |(key, val), hash| hash[key.to_sym] = val.is_a?(Hash) ? symbolize(val) : val end end |