class Draper::HelperProxy

Provides access to helper methods - both Rails built-in helpers, and those defined in your application.

Attributes

view_context[R]

Public Class Methods

new(view_context = nil) click to toggle source

@overload initialize(view_context)

# File lib/draper/helper_proxy.rb, line 7
def initialize(view_context = nil)
  view_context ||= current_view_context # backwards compatibility

  @view_context = view_context
end

Private Class Methods

define_proxy(name) click to toggle source
# File lib/draper/helper_proxy.rb, line 33
def self.define_proxy(name)
  define_method name do |*args, &block|
    view_context.send(name, *args, &block)
  end
end

Public Instance Methods

method_missing(method, *args, &block) click to toggle source

Sends helper methods to the view context.

# File lib/draper/helper_proxy.rb, line 14
def method_missing(method, *args, &block)
  self.class.define_proxy method
  send(method, *args, &block)
end
respond_to_missing?(method, include_private = false) click to toggle source

Checks if the context responds to an instance method, or is able to proxy it to the view context.

Calls superclass method
# File lib/draper/helper_proxy.rb, line 21
def respond_to_missing?(method, include_private = false)
  super || view_context.respond_to?(method)
end

Private Instance Methods

current_view_context() click to toggle source
# File lib/draper/helper_proxy.rb, line 39
def current_view_context
  ActiveSupport::Deprecation.warn("wrong number of arguments (0 for 1) passed to Draper::HelperProxy.new", caller[1..-1])
  Draper::ViewContext.current.view_context
end