Class: Draper::HelperProxy
- Inherits:
-
Object
- Object
- Draper::HelperProxy
- Defined in:
- lib/draper/helper_proxy.rb
Overview
Provides access to helper methods - both Rails built-in helpers, and those defined in your application.
Instance Method Summary collapse
-
#initialize(view_context) ⇒ HelperProxy
constructor
A new instance of HelperProxy.
-
#method_missing(method, *args, &block) ⇒ Object
Sends helper methods to the view context.
-
#respond_to_missing?(method, include_private = false) ⇒ Boolean
Checks if the context responds to an instance method, or is able to proxy it to the view context.
Constructor Details
#initialize(view_context) ⇒ HelperProxy
Returns a new instance of HelperProxy.
7 8 9 10 11 |
# 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 |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Sends helper methods to the view context.
14 15 16 17 |
# File 'lib/draper/helper_proxy.rb', line 14 def method_missing(method, *args, &block) self.class.define_proxy method send(method, *args, &block) end |
Instance Method Details
#respond_to_missing?(method, include_private = false) ⇒ Boolean
Checks if the context responds to an instance method, or is able to proxy it to the view context.
21 22 23 |
# File 'lib/draper/helper_proxy.rb', line 21 def respond_to_missing?(method, include_private = false) super || view_context.respond_to?(method) end |