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