Class: Langis::Middleware::MessageTypeFilter

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(app, *args) ⇒ MessageTypeFilter

Returns a new instance of MessageTypeFilter.

Parameters:

  • app

    The Rackish application chain to front.

  • ... (#to_s)

    The whitelist of message types to allow pass.



106
107
108
109
# File 'lib/langis/middleware.rb', line 106

def initialize(app, *args)
  @app = app
  @message_types = args.map { |message_type| message_type.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.

Parameters:

  • env (Hash)

    The Rackish input environment.

Returns:

  • (Array<Integer,Hash,#each>)

    The return of the proxied Rackish application chain, or an OK with the filter reason.

See Also:



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