Class: Muster::Rack
- Inherits:
-
Object
- Object
- Muster::Rack
- Defined in:
- lib/muster/rack.rb
Overview
Rack middleware plugin for Muster query string parsing
Constant Summary collapse
- QUERY =
Key in ENV where processed query string are stored
'muster.query'.freeze
- QUERY_STRING =
Key in ENV where the query string that was processed is stored
'muster.query_string'.freeze
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Rack application middleware is running under.
-
#options ⇒ Hash
readonly
Options to pass to strategy.
-
#strategy ⇒ Muster::Strategies::Rack
readonly
Muster Strategy to run.
Instance Method Summary collapse
-
#call(env) ⇒ Array
Handle Rack request.
-
#initialize(app, strategy, options = {}) ⇒ Rack
constructor
Creates a new Rack::Muster middleware instance.
Constructor Details
#initialize(app, strategy, options = {}) ⇒ Rack
Creates a new Rack::Muster middleware instance
48 49 50 51 52 |
# File 'lib/muster/rack.rb', line 48 def initialize(app, strategy, = {}) @app = app @strategy = strategy = end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns Rack application middleware is running under.
20 21 22 |
# File 'lib/muster/rack.rb', line 20 def app @app end |
#options ⇒ Hash (readonly)
Returns options to pass to strategy.
28 29 30 |
# File 'lib/muster/rack.rb', line 28 def end |
#strategy ⇒ Muster::Strategies::Rack (readonly)
Returns Muster Strategy to run.
24 25 26 |
# File 'lib/muster/rack.rb', line 24 def strategy @strategy end |
Instance Method Details
#call(env) ⇒ Array
Handle Rack request
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/muster/rack.rb', line 59 def call(env) # rubocop:disable Metrics/AbcSize request = ::Rack::Request.new(env) parser = strategy.is_a?(Class) ? strategy.new() : strategy env[QUERY] ||= Muster::Results.new({}) env[QUERY].merge! parser.parse(request.query_string) env[QUERY_STRING] = request.query_string @app.call(env) end |