Class: VCLog::Release

Inherits:
Object
  • Object
show all
Defined in:
lib/vclog/release.rb

Overview

A Release encapsulate a collection of Change objects associated with a Tag.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag, changes) ⇒ Release

New Release object.

Parameters:

  • tag (Tag)

    A Tag object.

  • changes (Array<Change>)

    An array of Change objects.



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

def initialize(tag, changes)
  @tag     = tag
  @changes = changes
end

Instance Attribute Details

#changesObject (readonly)

Array of Change objects.



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

def changes
  @changes
end

#tagObject (readonly)

Tag object this release represents.



9
10
11
# File 'lib/vclog/release.rb', line 9

def tag
  @tag
end

Instance Method Details

#<=>(other) ⇒ Object

Compare release by tag.

Parameters:

  • other (Release)

    Another release instance.



46
47
48
# File 'lib/vclog/release.rb', line 46

def <=>(other)
  @tag <=> other.tag
end

#groupsArray<Array>

Group changes by type and sort by level.

Returns:

  • (Array<Array>)

    Returns an associative array of [type, changes].



34
35
36
37
38
# File 'lib/vclog/release.rb', line 34

def groups
  @groups ||= (
    changes.group_by{ |e| e.label }.sort{ |a,b| b[1][0].level <=> a[1][0].level }
  )
end

#to_hObject

TODO:

Should version be name?

Convert Release to Hash.



55
56
57
58
59
60
61
62
63
# File 'lib/vclog/release.rb', line 55

def to_h
  { 'version'  => tag.name,
    'date'     => tag.date,
    'message'  => tag.message,
    'author'   => tag.author,
    'id'       => tag.id,
    'changes'  => changes.map{|change| change.to_h}
  }
end