Sha256: 2c56e15cbde617a8fa41bb93b5932a864c1004445d6d8e820a2fbaa8d5b57f5b

Contents?: true

Size: 1.43 KB

Versions: 5

Compression:

Stored size: 1.43 KB

Contents

module Mercurial
  
  #
  # The class represents Mercurial blame output (+hg blame+ command).
  #
  # This class is for Blame object itself, {Mercurial::BlameFactory BlameFactory} is responsible
  # for assembling instances of Blame. For the list of all possible blame-related operations 
  # check {Mercurial::BlameFactory BlameFactory}.
  #
  class Blame

    METADATA_RE = /^(.+) (\w{12}): *(\d+): /
    METADATA_AND_CODE_RE = /^(.+) (\w{12}): *(\d+): (.*)$/
    
    attr_reader :repository
    attr_reader :contents
    
    def initialize(repository, data)
      @repository = repository
      @contents = data
    end

    #
    # Returns code only as a String without the usual blame metadata.
    # Useful for code highlighting.
    #
    def contents_without_metadata
      contents.gsub(METADATA_RE, '')
    end

    #
    # Returns an Array of blame metadata for every line of blame.
    # Does not return code itself.
    #
    def raw_metadata
      contents.scan(METADATA_RE)
    end

    #
    # Returns an array of {Mercurial::BlameLine BlameLine} instances.
    #
    def lines
      [].tap do |result|
        contents.each_line do |line|
          author, revision, linenum, text = line.scan(METADATA_AND_CODE_RE).first
          result << BlameLine.new(
            :author   => author,
            :revision => revision,
            :num      => linenum,
            :contents => text
          )
        end
      end
    end
    
  end
  
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mercurial-ruby-0.7.12 lib/mercurial-ruby/blame.rb
mercurial-ruby-0.7.11 lib/mercurial-ruby/blame.rb
mercurial-ruby-0.7.10 lib/mercurial-ruby/blame.rb
mercurial-ruby-0.7.9 lib/mercurial-ruby/blame.rb
mercurial-ruby-0.7.8 lib/mercurial-ruby/blame.rb