Class: ReleaseHx::RHYML::Release

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

Overview

Represents a single versioned release containing metadata and associated changes. The Release class serves as a container for release metadata (version code, date, etc.) and manages a collection of Change objects that comprise the Release content.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code:, date: nil, hash: nil, memo: nil, changes: []) ⇒ Release

Initializes a new Release object.

Parameters:

  • code (String)
    The version code for the release (e.g., '1.2.0').
  • date (Date, String) (defaults to: nil)
    The release date.
  • hash (String) (defaults to: nil)
    The Git commit hash associated with the release.
  • memo (String) (defaults to: nil)
    A descriptive memo for the release.
  • changes (Array<Change, Hash>) (defaults to: [])
    An array of Change objects or Hashes to be converted into Change objects.


20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/releasehx/rhyml/release.rb', line 20

def initialize code:, date: nil, hash: nil, memo: nil, changes: []
  @code    = code
  @date    = date
  @hash    = hash
  @memo    = memo
  @changes = Array(changes).map { |ch| init_change(ch) }.compact

  ReleaseHx.logger.debug 'Release initialized with changes (post-compact):'
  @changes.each_with_index do |ch, i|
    ReleaseHx.logger.debug "  changes[#{i}]: #{ch.class}" unless ch.nil?
  end
  raise 'Unexpected nil in changes' if @changes.any?(&:nil?)
end

Instance Attribute Details

#changesObject (readonly)

Returns the value of attribute changes.


10
11
12
# File 'lib/releasehx/rhyml/release.rb', line 10

def changes
  @changes
end

#codeObject (readonly)

Returns the value of attribute code.


10
11
12
# File 'lib/releasehx/rhyml/release.rb', line 10

def code
  @code
end

#dateObject (readonly)

Returns the value of attribute date.


10
11
12
# File 'lib/releasehx/rhyml/release.rb', line 10

def date
  @date
end

#hashObject (readonly)

Returns the value of attribute hash.


10
11
12
# File 'lib/releasehx/rhyml/release.rb', line 10

def hash
  @hash
end

#memoObject (readonly)

Returns the value of attribute memo.


10
11
12
# File 'lib/releasehx/rhyml/release.rb', line 10

def memo
  @memo
end

Instance Method Details

#add_change(change) ⇒ Array<Change>

Adds a Change object to the Release.

Parameters:

  • change (Change)
    The Change object to add.

Returns:

  • (Array<Change>)
    The updated array of Changes.


38
39
40
41
# File 'lib/releasehx/rhyml/release.rb', line 38

def add_change change
  attach_release(change)
  @changes << change
end

#change_countInteger

Returns the number of Changes in the Release.

Returns:

  • (Integer)
    The count of Changes.


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

def change_count
  changes.size
end

#contributorsArray<String>

Retrieves a unique, sorted list of contributor logins for the Release.

Returns:

  • (Array<String>)
    An array of unique contributor names.


53
54
55
# File 'lib/releasehx/rhyml/release.rb', line 53

def contributors
  changes.map(&:lead).compact.uniq
end

#tag_statsHash{String => Integer}

Calculates a hash with the count of each tag used in the Release.

Returns:

  • (Hash{String => Integer})
    A hash where keys are tag names and values are their counts.


61
62
63
# File 'lib/releasehx/rhyml/release.rb', line 61

def tag_stats
  changes.compact.flat_map { |c| c.tags || [] }.tally
end

#to_hHash

Note:
This method excludes the Changes array from the output.
Converts the Release metadata to a hash representation.

Returns:

  • (Hash)
    A hash containing the Release's metadata fields.


69
70
71
72
73
74
75
76
77
78
79
# File 'lib/releasehx/rhyml/release.rb', line 69

def to_h
  {
    'code' => code,
    'version' => code, # alias for backward compatibility
    'date' => date,
    'hash' => hash,
    'memo' => memo,
    'tag_stats' => tag_stats,
    'contributors' => contributors
  }.compact
end