Class: Opts::Builder
- Inherits:
-
Object
- Object
- Opts::Builder
- Defined in:
- lib/opts/builder.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
Returns the value of attribute app.
Instance Method Summary collapse
- #call(env, args) ⇒ Object
-
#initialize(app = nil, &block) ⇒ Builder
constructor
A new instance of Builder.
- #run(app) ⇒ Object
- #to_app ⇒ Object
- #use(klass, *args, &block) ⇒ Object
Constructor Details
#initialize(app = nil, &block) ⇒ Builder
Returns a new instance of Builder.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/opts/builder.rb', line 5 def initialize(app=nil, &block) @app = app @ops = [] if block and block.arity == -1 instance_eval(&block) elsif block_given? yield(self) end end |
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
3 4 5 |
# File 'lib/opts/builder.rb', line 3 def app @app end |
Instance Method Details
#call(env, args) ⇒ Object
37 38 39 |
# File 'lib/opts/builder.rb', line 37 def call(env, args) to_app.call(env, args) end |
#run(app) ⇒ Object
20 21 22 |
# File 'lib/opts/builder.rb', line 20 def run(app) @app = app end |
#to_app ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/opts/builder.rb', line 24 def to_app @target ||= begin @ops.reverse.inject(@app) do |app, (klass, args, block)| if Class === klass klass.new(app, *args, &block) else klass.app = app klass end end end end |
#use(klass, *args, &block) ⇒ Object
16 17 18 |
# File 'lib/opts/builder.rb', line 16 def use(klass, *args, &block) @ops << [klass, args, block] end |