Class: Isono::Rack::Builder
- Inherits:
-
Object
- Object
- Isono::Rack::Builder
- Defined in:
- lib/isono/rack/builder.rb
Instance Method Summary collapse
- #call(req, res) ⇒ Object
-
#initialize(&blk) ⇒ Builder
constructor
A new instance of Builder.
- #map(command, app = nil, &blk) ⇒ Object
- #run(app) ⇒ Object
- #use(decorator_class, *args) ⇒ Object
Constructor Details
Instance Method Details
#call(req, res) ⇒ Object
34 35 36 37 |
# File 'lib/isono/rack/builder.rb', line 34 def call(req, res) raise "main app is not set" if @app.nil? @filters.reverse.inject(@app) {|d, f| f.call(d) }.call(req, res) end |
#map(command, app = nil, &blk) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/isono/rack/builder.rb', line 22 def map(command, app=nil, &blk) raise ArgumentError if app && blk if app raise TypeError unless app.respond_to?(:call) @app.map(command, app) elsif blk @app.map(command, self.class.new(&blk)) else raise ArgumentError end end |
#run(app) ⇒ Object
17 18 19 20 |
# File 'lib/isono/rack/builder.rb', line 17 def run(app) raise TypeError unless app.respond_to?(:call) @app.map('', app) end |
#use(decorator_class, *args) ⇒ Object
12 13 14 15 |
# File 'lib/isono/rack/builder.rb', line 12 def use(decorator_class, *args) raise TypeError unless decorator_class < Decorator @filters << lambda {|disp| decorator_class.new(disp, *args) } end |