Class: AutoViewModel::Base

Inherits:
Object
  • Object
show all
Includes:
Attributes
Defined in:
lib/auto_view_model/base.rb

Instance Method Summary collapse

Constructor Details

#initialize(local_assigns, view_context:) ⇒ Base

Returns a new instance of Base.



11
12
13
14
# File 'lib/auto_view_model/base.rb', line 11

def initialize(local_assigns, view_context:)
  super(local_assigns)
  @view_context = view_context
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

View models should support helper methods available in the template. By delegating missing methods to view context, we can support all existing Rails and application defined helpers.



20
21
22
23
24
25
26
# File 'lib/auto_view_model/base.rb', line 20

def method_missing(method, *args, &block)
  if @view_context.respond_to?(method)
    @view_context.public_send(method, *args, &block)
  else
    super
  end
end

Instance Method Details

#respond_to_missing?(method, include_all) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/auto_view_model/base.rb', line 29

def respond_to_missing?(method, include_all)
  @view_context.respond_to?(method, include_all)
end