Class: Langis::Middleware::MessageTypeFilter
- Inherits:
-
Object
- Object
- Langis::Middleware::MessageTypeFilter
- Defined in:
- lib/langis/middleware.rb
Overview
Middleware to only continue execution of the Rackish application chain if the input environment’s Langis::MESSAGE_TYPE_KEY is set to a value that has been whitelisted.
Instance Method Summary collapse
-
#call(env) ⇒ Array<Integer,Hash,#each>
Executes the filtering, and invokes the rest of the Rackish app chain if the message type is allowed.
-
#initialize(app, *args) ⇒ MessageTypeFilter
constructor
A new instance of MessageTypeFilter.
Constructor Details
#initialize(app, *args) ⇒ MessageTypeFilter
Returns a new instance of MessageTypeFilter.
106 107 108 109 |
# File 'lib/langis/middleware.rb', line 106 def initialize(app, *args) @app = app @message_types = args.map { || .to_s } end |
Instance Method Details
#call(env) ⇒ Array<Integer,Hash,#each>
Executes the filtering, and invokes the rest of the Rackish app chain if the message type is allowed.
120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/langis/middleware.rb', line 120 def call(env) if @message_types.include? env[MESSAGE_TYPE_KEY] return @app.call(env) else return [ OK, { X_FILTERED_BY => self.class.to_s, X_FILTERED_TYPE => env[MESSAGE_TYPE_KEY].class }, ['']] end end |