Class: Sparrow::Strategies::FormHash
- Inherits:
-
Object
- Object
- Sparrow::Strategies::FormHash
- Includes:
- Transformable
- Defined in:
- lib/sparrow/strategies/form_hash.rb
Overview
Handles Form Hash transformations, i.e. HTTP messages that contain form data
Instance Attribute Summary collapse
-
#env ⇒ Hash
readonly
The Rack environment.
-
#type ⇒ Symbol
readonly
The HTTP message type.
Class Method Summary collapse
-
.handle(env, type) ⇒ Object
Shortcut for handling a HTTP Message with this strategy.
Instance Method Summary collapse
-
#handle ⇒ Hash
Do the transformation.
-
#initialize(env, type = :request, params = nil) ⇒ FormHash
constructor
Create a new FormHash Strategy.
-
#params ⇒ Hash
If given in the constructor, this simply returns the given params argument.
Methods included from Transformable
Constructor Details
#initialize(env, type = :request, params = nil) ⇒ FormHash
Create a new FormHash Strategy
28 29 30 31 32 |
# File 'lib/sparrow/strategies/form_hash.rb', line 28 def initialize(env, type = :request, params = nil) @env = env @params = params @type = type end |
Instance Attribute Details
#env ⇒ Hash (readonly)
Returns the Rack environment.
11 12 13 |
# File 'lib/sparrow/strategies/form_hash.rb', line 11 def env @env end |
#type ⇒ Symbol (readonly)
Returns the HTTP message type. Either :request, or :response.
14 15 16 |
# File 'lib/sparrow/strategies/form_hash.rb', line 14 def type @type end |
Class Method Details
.handle(env, type) ⇒ Object
Shortcut for handling a HTTP Message with this strategy.
18 19 20 |
# File 'lib/sparrow/strategies/form_hash.rb', line 18 def self.handle(env, type) self.new(env, type).handle end |
Instance Method Details
#handle ⇒ Hash
Do the transformation
37 38 39 40 |
# File 'lib/sparrow/strategies/form_hash.rb', line 37 def handle super handle_form_hash end |
#params ⇒ Hash
If given in the constructor, this simply returns the given params argument. Otherwise it will look in the #env for form hash data params
47 48 49 |
# File 'lib/sparrow/strategies/form_hash.rb', line 47 def params @params || env[HttpMessage::FORM_HASH_KEY] end |