Class: FitCommit::Validators::Base

Inherits:
Object
  • Object
show all
Includes:
HasErrors
Defined in:
lib/fit_commit/validators/base.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

.allObject

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_nameObject

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

#configObject

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

Returns:

  • (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

Returns:

  • (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_lineObject



26
27
28
# File 'lib/fit_commit/validators/base.rb', line 26

def validate_line(*)
  fail NotImplementedError, "Implement in subclass"
end