Class: Merb::Router::Behavior::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/merb-core/dispatch/router/behavior.rb

Overview

Proxy catches any methods and proxies them to the current behavior. This allows building routes without constantly having to catching the yielded behavior object


Instance Method Summary collapse

Constructor Details

#initializeProxy

Returns a new instance of Proxy.



19
20
21
# File 'lib/merb-core/dispatch/router/behavior.rb', line 19

def initialize
  @behaviors = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)



71
72
73
74
75
76
77
78
79
# File 'lib/merb-core/dispatch/router/behavior.rb', line 71

def method_missing(method, *args, &block)
  behavior = @behaviors.last
  
  if behavior.respond_to?(method)
    behavior.send(method, *args, &block)
  else
    super
  end
end

Instance Method Details

#popObject



27
28
29
# File 'lib/merb-core/dispatch/router/behavior.rb', line 27

def pop
  @behaviors.pop
end

#push(behavior) ⇒ Object



23
24
25
# File 'lib/merb-core/dispatch/router/behavior.rb', line 23

def push(behavior)
  @behaviors.push(behavior)
end

#redirect(url, opts = {}) ⇒ Object



61
62
63
# File 'lib/merb-core/dispatch/router/behavior.rb', line 61

def redirect(url, opts = {})
  [url, opts[:permanent] ? 301 : 302]
end

#respond_to?(*args) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/merb-core/dispatch/router/behavior.rb', line 31

def respond_to?(*args)
  super || @behaviors.last.respond_to?(*args)
end

#route(params) ⇒ Object



65
66
67
# File 'lib/merb-core/dispatch/router/behavior.rb', line 65

def route(params)
  params
end

#url(name, *args) ⇒ Object

Generates a URL from the passed arguments. This method is for use inside of defer_to



56
57
58
59
# File 'lib/merb-core/dispatch/router/behavior.rb', line 56

def url(name, *args)
  args << {}
  Merb::Router.url(name, *args)
end