Module: ActiveDecorator::Helpers

Defined in:
lib/active_decorator/helpers.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/active_decorator/helpers.rb', line 6

def method_missing(method, *args, &block)
  super
rescue NoMethodError, NameError => e1
  # the error is not mine, so just releases it as is.
  raise e1 if e1.name != method

  if (view_context = ActiveDecorator::ViewContext.current)
    begin
      view_context.send method, *args, &block
    rescue NoMethodError => e2
      raise e2 if e2.name != method

      raise NoMethodError.new("undefined method `#{method}' for either #{self} or #{view_context}", method)
    rescue NameError => e2
      raise e2 if e2.name != method

      raise NameError.new("undefined local variable `#{method}' for either #{self} or #{view_context}", method)
    end
  else  # AC::API would have not view_context
    raise e1
  end
end