Class: Keela::Strategy
- Inherits:
-
Object
- Object
- Keela::Strategy
- 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.)
Direct Known Subclasses
Keela::Strategies::Attributes, Keela::Strategies::Constants, Keela::Strategies::Delegations, Keela::Strategies::I18nKeys, Keela::Strategies::Methods, Keela::Strategies::Scopes
Instance Method Summary collapse
-
#definition_file_pattern ⇒ Object
Regex pattern to match files that may contain definitions (e.g., /app/models/ for scopes).
-
#extract_definition(line) ⇒ Object
Extract a definition name from a line of code, or nil if no definition found.
-
#extract_definitions_from_file(_filepath, _lines) ⇒ Object
Override this method for strategies that need custom file parsing (e.g., YAML files for I18n keys).
-
#name ⇒ Object
Human-readable name for this strategy (e.g., "methods", "scopes").
-
#skip_comments? ⇒ Boolean
Whether to skip lines that start with # (comments).
-
#usage_regex(name) ⇒ Object
Build a regex to detect usage of the given definition name.
Instance Method Details
#definition_file_pattern ⇒ Object
Regex pattern to match files that may contain definitions (e.g., /app/models/ for scopes)
17 18 19 |
# File 'lib/keela/strategy.rb', line 17 def definition_file_pattern raise NotImplementedError, "#{self.class} must implement #definition_file_pattern" end |
#extract_definition(line) ⇒ Object
Extract a definition name from a line of code, or nil if no definition found
22 23 24 |
# File 'lib/keela/strategy.rb', line 22 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.
39 40 41 |
# File 'lib/keela/strategy.rb', line 39 def extract_definitions_from_file(_filepath, _lines) nil end |
#name ⇒ Object
Human-readable name for this strategy (e.g., "methods", "scopes")
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)
32 33 34 |
# File 'lib/keela/strategy.rb', line 32 def skip_comments? false end |
#usage_regex(name) ⇒ Object
Build a regex to detect usage of the given definition name
27 28 29 |
# File 'lib/keela/strategy.rb', line 27 def usage_regex(name) raise NotImplementedError, "#{self.class} must implement #usage_regex" end |