Sha256: 7df467b5dc94bf541c1bfec3606a17c1a1ba46d58f1ca430b716e4418bb0b9d6

Contents?: true

Size: 1.01 KB

Versions: 4

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

# On the fly delegation from the decorator to the decorated object and the helpers.
module ActiveDecorator
  module Helpers
    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
    ruby2_keywords :method_missing if respond_to?(:ruby2_keywords, true)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
active_decorator-1.4.1 lib/active_decorator/helpers.rb
active_decorator-1.4.0 lib/active_decorator/helpers.rb
active_decorator-1.3.4 lib/active_decorator/helpers.rb
active_decorator-1.3.3 lib/active_decorator/helpers.rb