Class: Keela::Strategy

Inherits:
Object
  • Object
show all
Defined in:
lib/keela/strategy.rb

Overview

Base class for detection strategies.

Subclasses define how to find definitions and detect usage for different types of code (methods, scopes, etc.)

Instance Method Summary collapse

Instance Method Details

#default_definition_file_patternObject

Default pattern when no configuration override is provided. Subclasses should implement this instead of definition_file_pattern.

Raises:

  • (NotImplementedError)


32
33
34
# File 'lib/keela/strategy.rb', line 32

def default_definition_file_pattern
  raise NotImplementedError, "#{self.class} must implement #default_definition_file_pattern"
end

#definition_file_patternObject

Regex pattern to match files that may contain definitions (e.g., /app/models/ for scopes)

Can be overridden via configuration:

strategies:
methods:
  definition_paths:
    - app/helpers
    - app/models
    - lib/


26
27
28
# File 'lib/keela/strategy.rb', line 26

def definition_file_pattern
  configured_pattern || default_definition_file_pattern
end

#extract_definition(line) ⇒ Object

Extract a definition name from a line of code, or nil if no definition found

Raises:

  • (NotImplementedError)


37
38
39
# File 'lib/keela/strategy.rb', line 37

def extract_definition(line)
  raise NotImplementedError, "#{self.class} must implement #extract_definition"
end

#extract_definitions_from_file(_filepath, _lines) ⇒ Object

Override this method for strategies that need custom file parsing (e.g., YAML files for I18n keys). Returns an array of { name:, file: } hashes, or nil to use default line-by-line parsing.



54
55
56
# File 'lib/keela/strategy.rb', line 54

def extract_definitions_from_file(_filepath, _lines)
  nil
end

#nameObject

Human-readable name for this strategy (e.g., "methods", "scopes")

Raises:

  • (NotImplementedError)


11
12
13
# File 'lib/keela/strategy.rb', line 11

def name
  raise NotImplementedError, "#{self.class} must implement #name"
end

#skip_comments?Boolean

Whether to skip lines that start with # (comments)

Returns:

  • (Boolean)


47
48
49
# File 'lib/keela/strategy.rb', line 47

def skip_comments?
  false
end

#usage_regex(name) ⇒ Object

Build a regex to detect usage of the given definition name

Raises:

  • (NotImplementedError)


42
43
44
# File 'lib/keela/strategy.rb', line 42

def usage_regex(name)
  raise NotImplementedError, "#{self.class} must implement #usage_regex"
end