Class: Langis::Dsl::RackishConfig
- Inherits:
-
Object
- Object
- Langis::Dsl::RackishConfig
- Includes:
- Blockenspiel::DSL
- Defined in:
- lib/langis/dsl.rb
Overview
A Dsl class used to define Rackish application stacks. This classes implementation is heavily inspired by Rack itself.
Example:
block = proc do
use Middleware, arg1, arg2
run lambda { |env| return [200, {}, env[:input1]] }
end
config = Langis::RackishConfig.new
Blockenspiel.invoke block, config
my_app = config.to_app
env = {
:input1 => 'Hello World'
}
results = my_app.call env
Instance Method Summary collapse
-
#initialize(app = nil) ⇒ RackishConfig
constructor
A new instance of RackishConfig.
-
#run(app) ⇒ Object
Dsl only method that defines the end point Rack app handler.
-
#to_app(app = nil) ⇒ #call
The method that actually wires up each middleware and the end point into a real Rack stack.
-
#use(middleware, *args, &block) ⇒ Object
Dsl only method that defines a piece of Middleware to run, in order, in this Rack-lik application.
Constructor Details
#initialize(app = nil) ⇒ RackishConfig
Returns a new instance of RackishConfig.
305 306 307 308 |
# File 'lib/langis/dsl.rb', line 305 def initialize(app=nil) @ins = [] @app = app ? app : lambda { |env| [OK, {}, [""]] } end |
Instance Method Details
#run(app) ⇒ Object
Dsl only method that defines the end point Rack app handler.
341 342 343 |
# File 'lib/langis/dsl.rb', line 341 def run(app) @app = app end |
#to_app(app = nil) ⇒ #call
The method that actually wires up each middleware and the end point into a real Rack stack.
317 318 319 320 |
# File 'lib/langis/dsl.rb', line 317 def to_app(app=nil) app ||= @app @ins.reverse.inject(app) { |a, e| e.call(a) } end |
#use(middleware, *args, &block) ⇒ Object
Dsl only method that defines a piece of Middleware to run, in order, in this Rack-lik application.
333 334 335 |
# File 'lib/langis/dsl.rb', line 333 def use(middleware, *args, &block) @ins << lambda { |app| middleware.new(app, *args, &block) } end |