Class: Langis::Middleware::EnvFieldTransform
- Inherits:
-
Object
- Object
- Langis::Middleware::EnvFieldTransform
- Defined in:
- lib/langis/middleware.rb
Overview
Middleware class that modifies the Rackish input environment by transforming a specific value in the environment before passing it along to the rest of the Rackish application chain.
Some useful applications of this transform:
-
Serialization or Deserialization of input data.
-
Filter or modify the message; to explicitly whitelist the list of properties in the message that may be exposed to a service or third party.
Instance Method Summary collapse
-
#call(env) ⇒ Array<Integer,Hash,#each>
Executes the object transformation, and invokes the rest of the Rackish app chain.
-
#initialize(app, options = {}) ⇒ EnvFieldTransform
constructor
A new instance of EnvFieldTransform.
Constructor Details
#initialize(app, options = {}) ⇒ EnvFieldTransform
Returns a new instance of EnvFieldTransform.
30 31 32 33 34 35 36 |
# File 'lib/langis/middleware.rb', line 30 def initialize(app, ={}) @app = app @to_method = [:to_method] || :to_json @to_args = [:to_args] || [] @to_args = [@to_args] unless @to_args.is_a? Array @key = [:key] || MESSAGE_KEY end |
Instance Method Details
#call(env) ⇒ Array<Integer,Hash,#each>
Executes the object transformation, and invokes the rest of the Rackish app chain.
45 46 47 48 |
# File 'lib/langis/middleware.rb', line 45 def call(env) item = env[@key].send @to_method, *@to_args return @app.call env.merge({ @key => item }) end |