module Jellyfish::NormalizedParams

Attributes

params[R]

Public Instance Methods

block_call(argument, block) click to toggle source
Calls superclass method
# File lib/jellyfish/normalized_params.rb, line 9
def block_call argument, block
  initialize_params(argument)
  super
end

Private Instance Methods

force_encoding(data, encoding=Encoding.default_external) click to toggle source

stolen from sinatra Fixes encoding issues by casting params to Encoding.default_external

# File lib/jellyfish/normalized_params.rb, line 43
def force_encoding(data, encoding=Encoding.default_external)
  return data if data.respond_to?(:rewind) # e.g. Tempfile, File, etc
  if data.respond_to?(:force_encoding)
    data.force_encoding(encoding).encode!
  elsif data.respond_to?(:each_value)
    data.each_value{ |v| force_encoding(v, encoding) }
  elsif data.respond_to?(:each)
    data.each{ |v| force_encoding(v, encoding) }
  end
  data
end
indifferent_hash() click to toggle source

stolen from sinatra Creates a Hash with indifferent access.

# File lib/jellyfish/normalized_params.rb, line 37
def indifferent_hash
  Hash.new {|hash,key| hash[key.to_s] if Symbol === key }
end
indifferent_params(params) click to toggle source

stolen from sinatra Enable string or symbol key access to the nested params hash.

# File lib/jellyfish/normalized_params.rb, line 27
def indifferent_params(params)
  params = indifferent_hash.merge(params)
  params.each do |key, value|
    next unless value.is_a?(Hash)
    params[key] = indifferent_params(value)
  end
end
initialize_params(argument) click to toggle source
# File lib/jellyfish/normalized_params.rb, line 15
def initialize_params argument
  @params = force_encoding(indifferent_params(
  if argument.kind_of?(MatchData)
    # merge captured data from matcher into params as sinatra
    request.params.merge(Hash[argument.names.zip(argument.captures)])
  else
    request.params
  end))
end