class Sparrow::Strategies::FormHash
Handles Form Hash transformations, i.e. HTTP messages that contain form data
Attributes
env[R]
@return [Hash] the Rack environment @see initialize
type[R]
@return [Symbol] the HTTP message type. Either :request, or :response @see initialize
Public Class Methods
handle(env, type)
click to toggle source
Shortcut for handling a HTTP Message with this strategy.
# File lib/sparrow/strategies/form_hash.rb, line 18 def self.handle(env, type) self.new(env, type).handle end
new(env, type = :request, params = nil)
click to toggle source
Create a new FormHash
Strategy @param [Hash] env the Rack environment @param [Symbol] type the HTTP message type. Must be either :request or
:response
@param [Hash] params the HTTP message parameters to be transformed
if not already present in the env
# File lib/sparrow/strategies/form_hash.rb, line 28 def initialize(env, type = :request, params = nil) @env = env @params = params @type = type end
Public Instance Methods
handle()
click to toggle source
Do the transformation @return [Hash] the converted JSON as a Hash representation
Calls superclass method
Sparrow::Transformable#handle
# File lib/sparrow/strategies/form_hash.rb, line 37 def handle super handle_form_hash end
params()
click to toggle source
If given in the constructor, this simply returns the given params argument. Otherwise it will look in the env
for form hash data params @return [Hash] the HTTP message params @see initialize
# File lib/sparrow/strategies/form_hash.rb, line 47 def params @params || env[HttpMessage::FORM_HASH_KEY] end
Private Instance Methods
handle_form_hash()
click to toggle source
# File lib/sparrow/strategies/form_hash.rb, line 53 def handle_form_hash env[HttpMessage::FORM_HASH_KEY] = transform_params if params.present? end