class Git::Cop::Commits::Unsaved
Represents a partially formed, unsaved commit.
Constants
- SCISSOR_PATTERN
Attributes
path[R]
raw_body[R]
shell[R]
Public Class Methods
new(path:, shell: Open3)
click to toggle source
# File lib/git/cop/commits/unsaved.rb, line 18 def initialize path:, shell: Open3 @path = Pathname path @shell = shell @raw_body = File.read path rescue Errno::ENOENT raise Errors::Base, %(Invalid commit message path: "#{path}".) end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/git/cop/commits/unsaved.rb, line 71 def <=> other raw_body <=> other.raw_body end
==(other)
click to toggle source
# File lib/git/cop/commits/unsaved.rb, line 66 def == other other.is_a?(self.class) && raw_body == other.raw_body end
Also aliased as: eql?
body()
click to toggle source
:reek: FeatureEnvy
# File lib/git/cop/commits/unsaved.rb, line 50 def body lines = raw_body.sub(SCISSOR_PATTERN, "").split("\n").drop(1) computed_body = lines.join("\n") lines.empty? ? computed_body : "#{computed_body}\n" end
body_lines()
click to toggle source
# File lib/git/cop/commits/unsaved.rb, line 56 def body_lines body.split("\n").reject { |line| line.start_with?("#") } end
body_paragraphs()
click to toggle source
:reek: FeatureEnvy
# File lib/git/cop/commits/unsaved.rb, line 61 def body_paragraphs lines = body.split("\n\n").map { |line| line.sub(/\A\n/, "") } lines.map(&:chomp).reject { |line| line.start_with?("#") } end
fixup?()
click to toggle source
# File lib/git/cop/commits/unsaved.rb, line 79 def fixup? subject.fixup? end
hash()
click to toggle source
# File lib/git/cop/commits/unsaved.rb, line 75 def hash raw_body.hash end
sha()
click to toggle source
:reek: UtilityFunction
# File lib/git/cop/commits/unsaved.rb, line 27 def sha SecureRandom.hex 20 end
squash?()
click to toggle source
# File lib/git/cop/commits/unsaved.rb, line 83 def squash? subject.squash? end
subject()
click to toggle source
# File lib/git/cop/commits/unsaved.rb, line 45 def subject String raw_body.split("\n").first end