Class: Keela::Strategies::Methods

Inherits:
Keela::Strategy show all
Defined in:
lib/keela/strategies/methods.rb

Instance Method Summary collapse

Methods inherited from Keela::Strategy

#additional_used_names, #definition_file_pattern, #extract_definitions_from_file

Instance Method Details

#default_definition_file_patternObject



10
11
12
# File 'lib/keela/strategies/methods.rb', line 10

def default_definition_file_pattern
  %r{app/helpers|app/models}
end

#extract_definition(line) ⇒ Object



14
15
16
17
18
# File 'lib/keela/strategies/methods.rb', line 14

def extract_definition(line)
  return nil unless line =~ /def ([^(;\s]+)/

  Regexp.last_match(1).chomp
end

#nameObject



6
7
8
# File 'lib/keela/strategies/methods.rb', line 6

def name
  "methods"
end

#skip_comments?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/keela/strategies/methods.rb', line 38

def skip_comments?
  false
end

#usage_regex(name) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/keela/strategies/methods.rb', line 20

def usage_regex(name)
  method_name = Regexp.quote(name.sub(/^self\./, ""))

  if name.end_with?("=")
    # Setter method: match assignment usage
    /(?<!def |def self\.)#{method_name.chomp("=")}\W=*/
  else
    # Regular method: match calls and symbol references
    # Matches:
    #   - Direct calls: foo(arg), obj.foo
    #   - Symbol references: :foo, :foo! (callbacks, send, etc.)
    # Excludes:
    #   - Definitions: def foo, def self.foo
    #   - Partial matches: :foobar, before_foo (via word boundary lookbehind)
    /(?<!def |def self\.)(?<![A-Za-z0-9_]):?#{method_name}(?:\W|$)/
  end
end