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

#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)


33
34
35
# File 'lib/keela/strategies/methods.rb', line 33

def skip_comments?
  false
end

#usage_regex(name) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# 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
    # Exclude both "def foo" and "def self.foo" definitions
    /(?<!def |def self\.)#{method_name}\W/
  end
end