class Git::Cop::Commits::Saved

Represents an existing commit.

Constants

FORMATS

Attributes

data[R]

Public Class Methods

new(sha:, shell: Open3) click to toggle source
# File lib/git/cop/commits/saved.rb, line 26
def initialize sha:, shell: Open3
  data, status = shell.capture2e show_command(sha)
  fail(Errors::SHA, sha) unless status.success?
  @data = data
end
pattern() click to toggle source
# File lib/git/cop/commits/saved.rb, line 22
def self.pattern
  FORMATS.reduce("") { |pattern, (key, value)| pattern + "<#{key}>#{value}</#{key}>%n" }
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/git/cop/commits/saved.rb, line 37
def <=> other
  sha <=> other.sha
end
==(other) click to toggle source
# File lib/git/cop/commits/saved.rb, line 32
def == other
  other.is_a?(self.class) && sha == other.sha
end
Also aliased as: eql?
body_lines() click to toggle source
# File lib/git/cop/commits/saved.rb, line 45
def body_lines
  body.split("\n").reject { |line| line.start_with?("#") }
end
body_paragraphs() click to toggle source
# File lib/git/cop/commits/saved.rb, line 49
def body_paragraphs
  body.split("\n\n").map(&:chomp).reject { |line| line.start_with?("#") }
end
eql?(other)
Alias for: ==
fixup?() click to toggle source
# File lib/git/cop/commits/saved.rb, line 53
def fixup?
  subject.fixup?
end
hash() click to toggle source
# File lib/git/cop/commits/saved.rb, line 41
def hash
  sha.hash
end
squash?() click to toggle source
# File lib/git/cop/commits/saved.rb, line 57
def squash?
  subject.squash?
end

Private Instance Methods

method_missing(name, *arguments, &block) click to toggle source
Calls superclass method
# File lib/git/cop/commits/saved.rb, line 69
def method_missing name, *arguments, &block
  return super unless FORMATS.keys.include?(name.to_sym)
  String data[%r(\<#{name}\>(?<content>.*?)\<\/#{name}\>)m, :content]
end
respond_to_missing?(name, include_private = false) click to toggle source
Calls superclass method
# File lib/git/cop/commits/saved.rb, line 74
def respond_to_missing? name, include_private = false
  FORMATS.keys.include?(name.to_sym) || super
end
show_command(sha) click to toggle source
# File lib/git/cop/commits/saved.rb, line 65
def show_command sha
  %(git show --stat --pretty=format:"#{self.class.pattern}" #{sha})
end