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
ROUTE_DSL_CALLS =
%i[
  collection concern concerns constraints controller defaults draw member mount namespace resource resources root scope
].to_set.merge(ROUTE_VERBS.map(&:to_sym)).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
INFLECTION_RULES_AFFECTING_PLURALIZATION =
%i[clear plural].freeze

Instance Method Summary collapse

Instance Method Details

#apply(graph, project) ⇒ Object



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
53
54
55
56
57
58
59
60
# File 'lib/necropsy/entry_points/rails.rb', line 18

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

  @route_blockers = []
  load_inflections(project)

  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.graph_id, :job_perform) if node.name == 'perform'
    when %r{\Aapp/mailers/}
      if node.kind == :instance_method && node.visibility == :public
        graph.add_entry_point(node.graph_id,
                              :mailer_action)
      end
    when %r{\Aapp/helpers/}
      graph.add_entry_point(node.graph_id, :rails_view_helper) if referenced_view_methods.include?(node.name)
    when %r{\Aapp/components/}
      graph.add_entry_point(node.graph_id, :rails_component) if component_entrypoint?(node)
    when %r{\Adb/migrate/}
      graph.add_entry_point(node.graph_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.graph_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.graph_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
  @route_blockers.each { |blocker| graph.add_blocker(blocker) }
end