Class: Rack::Transform
- Inherits:
-
Object
- Object
- Rack::Transform
- Defined in:
- lib/rack/transform.rb,
lib/rack/transform/version.rb,
lib/rack/transform/transformer.rb,
lib/rack/transform/transformers/base.rb
Defined Under Namespace
Modules: Transformers Classes: Transformer
Constant Summary collapse
- VERSION =
"0.1.1".freeze
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) {|_self| ... } ⇒ Transform
constructor
A new instance of Transform.
- #on(type, &block) ⇒ Object
Constructor Details
#initialize(app) {|_self| ... } ⇒ Transform
Returns a new instance of Transform.
5 6 7 8 9 |
# File 'lib/rack/transform.rb', line 5 def initialize(app) @app = app @transformers = {} yield self if block_given? end |
Instance Method Details
#call(env) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/rack/transform.rb', line 11 def call(env) if transformer = request_transformer(env) env = transformer.request.call(env) status, header, body = @app.call(env) transformer.response.call(status, header, body) else @app.call(env) end end |
#on(type, &block) ⇒ Object
21 22 23 |
# File 'lib/rack/transform.rb', line 21 def on(type, &block) @transformers[type] ||= Transformer.new(&block) end |