Class: AppMap::Handler::Rails::Template::ResolverHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/appmap/handler/rails/template.rb

Overview

Hooks the ActionView::Resolver methods find_all, find_all_anywhere. The resolver is used during template rendering to lookup the template file path from parameters such as the template name, prefix, and partial (boolean).

Class Method Summary collapse

Class Method Details

.handle_call(defined_class, hook_method, receiver, args) ⇒ Object

Handled as a normal function call.



97
98
99
100
101
102
# File 'lib/appmap/handler/rails/template.rb', line 97

def handle_call(defined_class, hook_method, receiver, args)
  name, prefix, partial = args
  warn "Resolver: #{{ name: name, prefix: prefix, partial: partial }}" if LOG

  AppMap::Handler::Function.handle_call(defined_class, hook_method, receiver, args)
end

.handle_return(call_event_id, elapsed, return_value, exception) ⇒ Object

When the resolver returns, look to see if there is template rendering underway. If so, populate the template path. In all cases, add a TemplateMethod so that the template will be recorded in the classMap.



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/appmap/handler/rails/template.rb', line 107

def handle_return(call_event_id, elapsed, return_value, exception)
  renderer = Array(Thread.current[TEMPLATE_RENDERER]).last
  path_obj = Array(return_value).first
  
  warn "Resolver return: #{path_obj}" if LOG

  if path_obj
    path = if path_obj.respond_to?(:identifier) && path_obj.inspect.index('#<')
      path_obj.identifier
    else
      path_obj.inspect
    end
    path = path[Dir.pwd.length + 1..-1] if path.index(Dir.pwd) == 0
    AppMap.tracing.record_method(TemplateMethod.new(path))
    renderer.path ||= path if renderer
  end

  AppMap::Handler::Function.handle_return(call_event_id, elapsed, return_value, exception)
end