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
IRREGULAR_PLURALS =
{ 'person' => 'people', 'man' => 'men', 'woman' => 'women', 'child' => 'children' }.freeze

Instance Method Summary collapse

Instance Method Details

#apply(graph, project) ⇒ Object



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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/necropsy/entry_points/rails.rb', line 14

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

  referenced_view_methods = view_method_names(project)
  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/}
      if node.kind == :instance_method && node.visibility == :public
        graph.add_entry_point(node.id,
                              :mailer_action)
      end
    when %r{\Aapp/helpers/}
      graph.add_entry_point(node.id, :rails_view_helper) if referenced_view_methods.include?(node.name)
    when %r{\Aapp/components/}
      graph.add_entry_point(node.id, :rails_component) if component_entrypoint?(node)
    when %r{\Adb/migrate/}
      graph.add_entry_point(node.id, :rails_migration) if %w[change up down].include?(node.name)
    end

    if node.file.start_with?('app/') && !node.file.start_with?('app/helpers/', 'app/components/') &&
       referenced_view_methods.include?(node.name)
      graph.add_entry_point(node.id, :rails_view_reference)
    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