Module: ActionWidget::ViewHelper

Defined in:
lib/action_widget/view_helper.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/action_widget/view_helper.rb', line 3

def method_missing(name, *args, &block)
  widget = ActionWidget[name]
  return super if widget.nil?

  ActionWidget::ViewHelper.module_eval <<-RUBY
    def #{name}(*args, &block)                          # def example_widget(*args, &block)
      attrs = args.last.kind_of?(Hash) ? args.pop : {}
      #{widget}.new(self, attrs).render(*args, &block)  #   ExampleWidget.new(self, attrs).render(*args, &block)
    end                                                 # end
  RUBY

  send(name, *args, &block)
end

Instance Method Details

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/action_widget/view_helper.rb', line 17

def respond_to_missing?(name, include_private = false)
  !!ActionWidget[name] || super
end