Class: VCLog::Change

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/vclog/change.rb

Overview

The Change class models an entry in a change log.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ Change

Setup new Change instance.



43
44
45
46
47
48
49
50
51
52
# 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

Instance Attribute Details

#authorObject Also known as: who

Committer.



18
19
20
# File 'lib/vclog/change.rb', line 18

def author
  @author
end

#colorObject

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`.



40
41
42
# File 'lib/vclog/change.rb', line 40

def color
  @color
end

#dateObject

Date/time of commit.



15
16
17
# File 'lib/vclog/change.rb', line 15

def date
  @date
end

#detailsObject (readonly)

Returns the value of attribute details.



122
123
124
# File 'lib/vclog/change.rb', line 122

def details
  @details
end

#filesObject

List of files changed in the commit.



24
25
26
# File 'lib/vclog/change.rb', line 24

def files
  @files
end

#idObject Also known as: rev, revision, ref, reference

Commit revision/reference id.



12
13
14
# File 'lib/vclog/change.rb', line 12

def id
  @id
end

#labelObject

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



35
36
37
# File 'lib/vclog/change.rb', line 35

def label
  @label
end

#levelObject

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.



32
33
34
# File 'lib/vclog/change.rb', line 32

def level
  @level
end

#messageObject Also known as: msg

Commit message.



21
22
23
# File 'lib/vclog/change.rb', line 21

def message
  @message
end

#summaryObject (readonly)

Returns the value of attribute summary.



120
121
122
# File 'lib/vclog/change.rb', line 120

def summary
  @summary
end

#typeObject

Type of change, as assigned by hueristics.



27
28
29
# File 'lib/vclog/change.rb', line 27

def type
  @type
end

Instance Method Details

#<=>(other) ⇒ Object

Compare changes by date.



127
128
129
# File 'lib/vclog/change.rb', line 127

def <=>(other)
  other.date <=> date
end

#apply_heuristics(heuristics) ⇒ Object

Apply heuristic rules to change.



153
154
155
# File 'lib/vclog/change.rb', line 153

def apply_heuristics(heuristics)
  heuristics.apply(self)
end

#inspectObject

Inspection string of change object.



134
135
136
# File 'lib/vclog/change.rb', line 134

def inspect
  "#<Change:#{object_id} #{date}>"
end

#parse_date(date) ⇒ Object (private)

Convert given date into Time instance.

Parameters:

  • date (String, Data, Time)

    A valid data/time string or object.



184
185
186
187
188
189
190
191
# 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_pointsObject (private)

TODO:

Improve the parsing of point messages.

Split message into individual points.



198
199
200
201
202
203
# 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

#pointsObject

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



161
162
163
# File 'lib/vclog/change.rb', line 161

def points
  @points ||= parse_points
end

#to_hObject

Convert to Hash.



141
142
143
144
145
146
147
148
# 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 = {}) ⇒ Object

Output message with optional adjustments.



168
169
170
171
172
173
174
# File 'lib/vclog/change.rb', line 168

def to_s(opts={})
  if opts[:summary]
    summary
  else
    message.strip
  end
end