Sha256: edeadc781f0c2940f2fef1a2db207afce4328f5f613d5b82f3fbde5634e08e70

Contents?: true

Size: 567 Bytes

Versions: 3

Compression:

Stored size: 567 Bytes

Contents

# frozen_string_literal: true

module Rack
  module Reducer
    # convert params from Sinatra, Rails, Roda, etc into a symbol hash
    module Parser
      def self.call(data)
        data.is_a?(Hash) ? data : hashify(data)
      end

      # 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
      def self.hashify(data)
        fn = %i[to_unsafe_h to_h].find { |name| data.respond_to?(name) }
        data.send(fn)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rack-reducer-0.1.2 lib/rack/reducer/parser.rb
rack-reducer-0.1.1 lib/rack/reducer/parser.rb
rack-reducer-0.1.0 lib/rack/reducer/parser.rb