class VCLog::Change

The Change class models an entry in a change log.

Attributes

author[RW]

Committer.

color[RW]

ANSI color to apply. Actually this can be a list of any support ansi gem terms, but usually it’s just the color term, such as ‘:red`.

date[RW]

Date/time of commit.

details[R]
files[RW]

List of files changed in the commit.

id[RW]

Commit revision/reference id.

label[RW]

The descriptive label of this change, as assigned by hueristics.

level[RW]

The priority level of this change, as assigned by hueristics. This can be ‘nil`, as Heuristics will always make sure a commit has an inteer level before going out to template.

message[RW]

Commit message.

msg[RW]

Commit message.

ref[RW]

Commit revision/reference id.

ref=[RW]

Commit revision/reference id.

reference[RW]

Commit revision/reference id.

reference=[RW]

Commit revision/reference id.

rev[RW]

Commit revision/reference id.

rev=[RW]

Commit revision/reference id.

revision[RW]

Commit revision/reference id.

revision=[RW]

Commit revision/reference id.

summary[R]
type[RW]

Type of change, as assigned by hueristics.

who[RW]

Committer.

Public Class Methods

new(data={}) click to toggle source

Setup new Change instance.

# File lib/vclog/change.rb, line 43
def initialize(data={})
  @type  = :default
  @level = nil
  @label = nil
  @color = []

  data.each do |k,v|
    __send__("#{k}=", v) if respond_to?("#{k}=")
  end
end

Public Instance Methods

<=>(other) click to toggle source

Compare changes by date.

# File lib/vclog/change.rb, line 127
def <=>(other)
  other.date <=> date
end
apply_heuristics(heuristics) click to toggle source

Apply heuristic rules to change.

# File lib/vclog/change.rb, line 153
def apply_heuristics(heuristics)
  heuristics.apply(self)
end
author=(author) click to toggle source

Set authors attributes, ensuring the value is stripped of white space.

# File lib/vclog/change.rb, line 57
def author=(author)
  @author = author.strip
end
Also aliased as: who=
color=(code) click to toggle source

Set the ANSI color terms.

@param [Symbol,Array<Symbol>] code

An ANSI gem recognized term, or array of such.
# File lib/vclog/change.rb, line 87
def color=(code)
  @color = [code].flatten
end
date=(date) click to toggle source

Set date attribute, converting vale given to an instance of Time.

# File lib/vclog/change.rb, line 64
def date=(date)
  @date = parse_date(date)
end
inspect() click to toggle source

Inspection string of change object.

# File lib/vclog/change.rb, line 134
def inspect
  "#<Change:#{object_id} #{date}>"
end
message=(msg) click to toggle source

Set the commit message.

# File lib/vclog/change.rb, line 71
def message=(msg)
  @message = msg

  lines = msg.lines.to_a
  @summary = lines.first.strip
  @details = lines[1..-1].join('').strip

  msg
end
Also aliased as: msg=
msg=(msg)
Alias for: message=
points() click to toggle source

Parse point entries from commit message. Point entries are outlined changes via line that start with an asterisk.

# File lib/vclog/change.rb, line 161
def points
  @points ||= parse_points
end
to_h() click to toggle source

Convert to Hash.

# File lib/vclog/change.rb, line 141
def to_h
  { 'author'   => self.author,
    'date'     => self.date,
    'id'       => self.id,
    'message'  => self.message,
    'type'     => self.type
  }
end
to_s(opts={}) click to toggle source

Output message with optional adjustments.

# File lib/vclog/change.rb, line 168
def to_s(opts={})
  if opts[:summary]
    summary
  else
    message.strip
  end
end
type=(type) click to toggle source
# File lib/vclog/change.rb, line 92
def type=(type)
  @type = type.to_sym
end
who=(author)
Alias for: author=

Private Instance Methods

parse_date(date) click to toggle source

Convert given date into Time instance.

@param [String,Data,Time] date

A valid data/time string or object.
# File lib/vclog/change.rb, line 184
def parse_date(date)
  case date
  when Time
    date
  else
    Time.parse(date.to_s)
  end
end
parse_points() click to toggle source

Split message into individual points.

@todo Improve the parsing of point messages.

# File lib/vclog/change.rb, line 198
def parse_points
  point_messages = message.split(/^\*/)
  point_messages.map do |msg|
    ChangePoint.new(self, msg)
  end
end