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

Class Method Details

.call(data) ⇒ Object



7
8
9
# File 'lib/rack/reducer/parser.rb', line 7

def self.call(data)
  data.is_a?(Hash) ? 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



14
15
16
17
# File 'lib/rack/reducer/parser.rb', line 14

def self.hashify(data)
  fn = %i[to_unsafe_h to_h].find { |name| data.respond_to?(name) }
  data.send(fn)
end