Module: Sinatra::Delegator

Defined in:
lib/sinatra/base.rb

Overview

Sinatra delegation mixin. Mixing this module into an object causes all methods to be delegated to the Sinatra::Application class. Used primarily at the top-level.

Constant Summary collapse

TEMPLATE =

:nodoc:

"  def %1$s(*args, &b)\n    return super if respond_to? :%1$s\n    ::Sinatra::Delegator.target.send(\"%2$s\", *args, &b)\n  end\n"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.targetObject

Returns the value of attribute target.



1499
1500
1501
# File 'lib/sinatra/base.rb', line 1499

def target
  @target
end

Class Method Details

.delegate(*methods) ⇒ Object



1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
# File 'lib/sinatra/base.rb', line 1475

def self.delegate(*methods)
  methods.each do |method_name|
    # Replaced with way shorter and better implementation in 1.3.0
    # using define_method instead, however, blocks cannot take block
    # arguments on 1.8.6.
    begin
      code = TEMPLATE % [method_name, method_name]
      eval code, binding, '(__DELEGATE__)', 1
    rescue SyntaxError
      code  = TEMPLATE % [:_delegate, method_name]
      eval code, binding, '(__DELEGATE__)', 1
      alias_method method_name, :_delegate
      undef_method :_delegate
    end
    private method_name
  end
end