Class: RuboCop::Cop::Jbuilder::PartialExists

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/jbuilder/partial_exists.rb

Constant Summary collapse

MSG =
"Partial not found. Looked for: %<paths>s"

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rubocop/cop/jbuilder/partial_exists.rb', line 20

def on_send(node)
  has_partial?(node) do |actual|
    all_globs = get_view_globs_from(actual)

    return if all_globs.any? { |glob| Dir.glob(glob).any? }

    base_path = rails_root_dirname(node)
    relative_paths = all_globs.map { |glob| relative_path(glob, base_path) }
    add_offense(actual, message: format(MSG, paths: relative_paths.join(", ")))
  end
end