class VCLog::HistoryFile

The HistoryFile class will parse a history into an array of release tags. Of course to do this, it assumes a specific file format.

Constants

CASEFOLD

Alias for ‘File::FNM_CASEFOLD`.

DATE
FILE
LINE
VERS

Attributes

tags[R]

Release tags.

Public Class Methods

new(source=nil) click to toggle source

Setup new HistoryFile instance.

# File lib/vclog/history_file.rb, line 22
def initialize(source=nil)
  if File.file?(source)
    @file = source
    @root = File.dirname(source)
  elsif File.directory?(source)
    @file = Dir.glob(File.join(source,FILE), CASEFOLD).first
    @root = source
  else
    @file = Dir.glob(FILE).first
    @root = Dir.pwd
  end
  raise "no history file" unless @file

  @tags = extract_tags
end

Public Instance Methods

extract_tags() click to toggle source

Parse history file.

# File lib/vclog/history_file.rb, line 39
def extract_tags
  tags = []
  desc = ''
  text = File.read(@file)
  text.lines.each do |line|
    if LINE =~ line
      vers = (VERS.match(line) || [])[0]
      date = (DATE.match(line) || [])[0]
      next unless vers
      tags << [vers, date, desc = '']
    else
      desc << line
    end
  end

  tags.map do |vers, date, desc|
    index = desc.index(/^Changes:/) || desc.index(/^\*/) || desc.size
    desc = desc[0...index].strip.fold
    #[vers, date, desc]
    Tag.new(:name=>vers, :date=>date, :msg=>desc)
  end
end
news() click to toggle source
# File lib/vclog/history_file.rb, line 63
def news
  tags.first.message
end