Class: LinterChanges::Linter::Base
- Inherits:
-
Object
- Object
- LinterChanges::Linter::Base
- Defined in:
- lib/linter/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#config_changed?(changed_files) ⇒ Boolean
Checks if any configuration files have changed.
-
#initialize(config_files: nil, command: nil, git_diff: nil) ⇒ Base
constructor
A new instance of Base.
-
#list_target_files ⇒ Object
Returns an array of files that the linter targets.
-
#run(files: []) ⇒ Object
Runs the linter on the specified files.
Constructor Details
#initialize(config_files: nil, command: nil, git_diff: nil) ⇒ Base
Returns a new instance of Base.
8 9 10 11 12 13 14 |
# File 'lib/linter/base.rb', line 8 def initialize(config_files: nil, command: nil, git_diff: nil) @name = self.class.name.split('::')[-2].downcase default_config_file = YAML.load_file("lib/linter/#{@name}/default_config.yml") @config_files = config_files || default_config_file['config_files'] @command = command || default_config_file['command'] @git_diff = git_diff end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/linter/base.rb', line 6 def name @name end |
Instance Method Details
#config_changed?(changed_files) ⇒ Boolean
Checks if any configuration files have changed
22 23 24 25 26 27 28 |
# File 'lib/linter/base.rb', line 22 def config_changed?(changed_files) changed = @config_files.any? do |pattern| changed_files.any? { |file| file.match? Regexp.new(pattern) } end Logger.debug "#{@name.capitalize} configuration changed: #{changed}" changed end |
#list_target_files ⇒ Object
Returns an array of files that the linter targets
17 18 19 |
# File 'lib/linter/base.rb', line 17 def list_target_files raise NotImplementedError, "#{self.class} must implement #list_target_files" end |
#run(files: []) ⇒ Object
Runs the linter on the specified files
31 32 33 |
# File 'lib/linter/base.rb', line 31 def run(files: []) raise NotImplementedError, "#{self.class} must implement #run" end |