Class: RakeCommit::CommitMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/rake_commit/commit_message.rb

Defined Under Namespace

Modules: MessageType

Constant Summary collapse

SUBJECT_MAX_LENGTH =
50

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prompt_exclusions = [], type = MessageType::MESSAGE) ⇒ CommitMessage

Returns a new instance of CommitMessage.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rake_commit/commit_message.rb', line 14

def initialize(prompt_exclusions = [], type = MessageType::MESSAGE)
  @author = RakeCommit::PromptLine.new("author", prompt_exclusions).prompt
  @feature = RakeCommit::PromptLine.new("feature", prompt_exclusions).prompt
  @message = case type
    when MessageType::MESSAGE
      RakeCommit::PromptLine.new("message", prompt_exclusions).prompt
    when MessageType::WHAT_AND_WHY
      what = RakeCommit::PromptLine.new("what", prompt_exclusions).prompt
      why = RakeCommit::PromptLine.new("why", prompt_exclusions).prompt

      subject_space_remaining = SUBJECT_MAX_LENGTH - @feature.length
      truncated_what = what[0...subject_space_remaining]
      subject = RakeCommit::PromptLine.new("subject", prompt_exclusions, truncated_what).prompt

      create_message_with_subject_what_and_why(subject, what, why)
    end
end

Instance Attribute Details

#authorObject (readonly)

Returns the value of attribute author.



12
13
14
# File 'lib/rake_commit/commit_message.rb', line 12

def author
  @author
end

#featureObject (readonly)

Returns the value of attribute feature.



12
13
14
# File 'lib/rake_commit/commit_message.rb', line 12

def feature
  @feature
end

#messageObject (readonly)

Returns the value of attribute message.



12
13
14
# File 'lib/rake_commit/commit_message.rb', line 12

def message
  @message
end

Instance Method Details

#joined_message(wrap = nil) ⇒ Object



32
33
34
35
36
# File 'lib/rake_commit/commit_message.rb', line 32

def joined_message(wrap = nil)
  message = [@feature, @message].compact.join(' - ')
  message = WordWrap.ww(message, wrap) if wrap
  message
end

#joined_message_with_author(wrap = nil) ⇒ Object



38
39
40
41
42
# File 'lib/rake_commit/commit_message.rb', line 38

def joined_message_with_author(wrap = nil)
  message = [@author, @feature, @message].compact.join(' - ')
  message = WordWrap.ww(message, wrap) if wrap
  message
end