Class: Sparrow::Strategies::Ignore
- Inherits:
-
Object
- Object
- Sparrow::Strategies::Ignore
- Includes:
- Transformable
- Defined in:
- lib/sparrow/strategies/ignore.rb
Overview
This strategy is called when the HTTP message shall not
be transformed, i.e. ignored. This is inspired by the NullObject-Pattern to be convenient.
Class Method Summary collapse
Instance Method Summary collapse
-
#handle ⇒ Hash
handles the conversion, i.e.
-
#initialize(env, type = :request, params = nil) ⇒ Ignore
constructor
Create a new IgnoreStrategy.
-
#json_body ⇒ Object
Alias for #params.
-
#params ⇒ Hash
Although we are ignoring any kind of conversion we still need to read the parameters from the environment to be convenient with all other calls in the chains and architecture sigh Checks env.
-
#transform_params ⇒ Hash
Transforms the params to a Ruby JSON Hash representation.
Constructor Details
#initialize(env, type = :request, params = nil) ⇒ Ignore
Create a new IgnoreStrategy
16 17 18 19 20 |
# File 'lib/sparrow/strategies/ignore.rb', line 16 def initialize(env, type = :request, params = nil) @env = env @params = params @type = type end |
Class Method Details
.handle(env, type) ⇒ Object
34 35 36 |
# File 'lib/sparrow/strategies/ignore.rb', line 34 def self.handle(env, type) new(env, type).handle end |
Instance Method Details
#handle ⇒ Hash
handles the conversion, i.e. here “do nothing” Which is not strictly true - at write the rack.input to the form hash key for convenience reasons to enable further middlewares to work with it
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/sparrow/strategies/ignore.rb', line 44 def handle # synchronize rack.input and form hash values input = @env[HttpMessage::RACK_INPUT_KEY].gets begin @env[HttpMessage::FORM_HASH_KEY] = JSON.parse(input) rescue JSON::ParserError # ignore ensure @env[HttpMessage::RACK_INPUT_KEY].rewind end if input.present? @env end |
#json_body ⇒ Object
Alias for #params
62 63 64 |
# File 'lib/sparrow/strategies/ignore.rb', line 62 def json_body params end |
#params ⇒ Hash
Although we are ignoring any kind of conversion we still need to read the parameters from the environment to be convenient with all other calls in the chains and architecture sigh Checks env
28 29 30 31 32 |
# File 'lib/sparrow/strategies/ignore.rb', line 28 def params ret = @params || @env[HttpMessage::RACK_INPUT_KEY].send(:read) @env[HttpMessage::RACK_INPUT_KEY].rewind ret end |
#transform_params ⇒ Hash
Transforms the params to a Ruby JSON Hash representation
69 70 71 |
# File 'lib/sparrow/strategies/ignore.rb', line 69 def transform_params ensure_json end |