Class: FitCommit::Validators::Base
- Inherits:
-
Object
- Object
- FitCommit::Validators::Base
- Includes:
- HasErrors
- Defined in:
- lib/fit_commit/validators/base.rb
Direct Known Subclasses
CapitalizeSubject, Frathouse, LineLength, SubjectPeriod, Tense, Wip
Class Attribute Summary collapse
-
.all ⇒ Object
Returns the value of attribute all.
Instance Attribute Summary collapse
-
#branch_name ⇒ Object
Returns the value of attribute branch_name.
-
#config ⇒ Object
Returns the value of attribute config.
Class Method Summary collapse
Instance Method Summary collapse
- #enabled? ⇒ Boolean
-
#initialize(branch_name, config) ⇒ Base
constructor
A new instance of Base.
- #matches_branch?(pattern) ⇒ Boolean
- #validate(lines) ⇒ Object
- #validate_line ⇒ Object
Methods included from HasErrors
#add_error, #add_warning, #clear_errors, #clear_warnings, #errors, #merge_errors, #merge_warnings, #warnings
Constructor Details
#initialize(branch_name, config) ⇒ Base
Returns a new instance of Base.
9 10 11 12 |
# File 'lib/fit_commit/validators/base.rb', line 9 def initialize(branch_name, config) self.branch_name = branch_name self.config = config end |
Class Attribute Details
.all ⇒ Object
Returns the value of attribute all.
16 17 18 |
# File 'lib/fit_commit/validators/base.rb', line 16 def all @all end |
Instance Attribute Details
#branch_name ⇒ Object
Returns the value of attribute branch_name.
8 9 10 |
# File 'lib/fit_commit/validators/base.rb', line 8 def branch_name @branch_name end |
#config ⇒ Object
Returns the value of attribute config.
8 9 10 |
# File 'lib/fit_commit/validators/base.rb', line 8 def config @config end |
Class Method Details
.inherited(subclass) ⇒ Object
17 18 19 |
# File 'lib/fit_commit/validators/base.rb', line 17 def inherited(subclass) all << subclass end |
Instance Method Details
#enabled? ⇒ Boolean
30 31 32 33 34 35 36 37 |
# File 'lib/fit_commit/validators/base.rb', line 30 def enabled? enabled_val = config.fetch("Enabled") if enabled_val.is_a?(Array) enabled_val.any? { |pattern| matches_branch?(pattern) } else enabled_val end end |
#matches_branch?(pattern) ⇒ Boolean
39 40 41 42 43 44 45 |
# File 'lib/fit_commit/validators/base.rb', line 39 def matches_branch?(pattern) if pattern.is_a?(Regexp) pattern =~ branch_name else pattern == branch_name end end |
#validate(lines) ⇒ Object
22 23 24 |
# File 'lib/fit_commit/validators/base.rb', line 22 def validate(lines) lines.each { |line| validate_line(line.lineno, line.text) } end |
#validate_line ⇒ Object
26 27 28 |
# File 'lib/fit_commit/validators/base.rb', line 26 def validate_line(*) fail NotImplementedError, "Implement in subclass" end |