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
50 51 52 53 54 |
# File 'lib/muster/rack.rb', line 50 def initialize( app, strategy, ={} ) @app = app @strategy = strategy @options = end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns Rack application middleware is running under.
22 23 24 |
# File 'lib/muster/rack.rb', line 22 def app @app end |
#options ⇒ Hash (readonly)
Returns options to pass to strategy.
30 31 32 |
# File 'lib/muster/rack.rb', line 30 def @options end |
#strategy ⇒ Muster::Strategies::Rack (readonly)
Returns Muster Strategy to run.
26 27 28 |
# File 'lib/muster/rack.rb', line 26 def strategy @strategy end |
Instance Method Details
#call(env) ⇒ Array
Handle Rack request
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/muster/rack.rb', line 61 def call( env ) request = ::Rack::Request.new(env) parser = self.strategy.kind_of?(Class) ? self.strategy.new() : self.strategy env[QUERY] ||= Muster::Results.new({}) env[QUERY].merge! parser.parse(request.query_string) env[QUERY_STRING] = request.query_string @app.call(env) end |