Class: SubjectLengthCheck

Inherits:
CommitCheck show all
Defined in:
lib/wcc/commit_lint/subject_length_check.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CommitCheck

fail?

Constructor Details

#initialize(message, options = {}) ⇒ SubjectLengthCheck

Returns a new instance of SubjectLengthCheck.



8
9
10
11
12
# File 'lib/wcc/commit_lint/subject_length_check.rb', line 8

def initialize(message, options = {})
  @subject = message[:subject]
  @max_length = options.fetch(:max, 50)
  @min_length = options.fetch(:min, 1)
end

Class Method Details

.typeObject



4
5
6
# File 'lib/wcc/commit_lint/subject_length_check.rb', line 4

def self.type
  :subject_length
end

Instance Method Details

#fail?Boolean

Returns:

  • (Boolean)


23
24
25
26
# File 'lib/wcc/commit_lint/subject_length_check.rb', line 23

def fail?
  @subject.length > @max_length ||
    @subject.length < @min_length
end

#messageObject



14
15
16
17
18
19
20
21
# File 'lib/wcc/commit_lint/subject_length_check.rb', line 14

def message
  if @subject.length > @max_length
    "Please limit commit subject line to #{@max_length} characters."
  else
    "Please write a commit subject line of at least #{@min_length} "\
      'characters.'
  end
end