Class: Necropsy::EntryPoints::Rails

Inherits:
Object
  • Object
show all
Defined in:
lib/necropsy/entry_points/rails.rb

Defined Under Namespace

Classes: RouteContext

Constant Summary collapse

ROUTE_VERBS =
%w[get post put patch delete match].freeze
RESTFUL_ACTIONS =
%w[index show new create edit update destroy].freeze
SINGULAR_ACTIONS =
%w[show new create edit update destroy].freeze

Instance Method Summary collapse

Instance Method Details

#apply(graph, project) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/necropsy/entry_points/rails.rb', line 11

def apply(graph, project)
  return unless project.config.rails_enabled?

  graph.method_nodes.each do |node|
    case node.file
    when %r{\Aapp/jobs/}
      graph.add_entry_point(node.id, :job_perform) if node.name == 'perform'
    when %r{\Aapp/mailers/}
      graph.add_entry_point(node.id, :mailer_action) if node.kind == :instance_method
    when %r{\Aapp/helpers/}
      graph.add_entry_point(node.id, :rails_view_helper) if helper_referenced?(project, node.name)
    when %r{\Aapp/components/}
      graph.add_entry_point(node.id, :rails_component) if component_entrypoint?(node)
    end
  end

  graph.nodes.values.select do |node|
    node.kind == :block_entry && node.file.start_with?('config/initializers/')
  end.each do |node|
    graph.add_entry_point(node.id, :callback_registered)
  end

  route_entry_points(project).each do |node_id|
    matching_route_nodes(graph, node_id).each do |matching_id|
      graph.add_entry_point(matching_id, :rails_route)
    end
  end
end