Class: ReleaseHx::RHYML::Release
- Inherits:
-
Object
- Object
- ReleaseHx::RHYML::Release
- 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
-
#changes ⇒ Object
readonly
Returns the value of attribute changes.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
-
#memo ⇒ Object
readonly
Returns the value of attribute memo.
Instance Method Summary collapse
-
#add_change(change) ⇒ Array<Change>
Adds a Change object to the Release.
-
#change_count ⇒ Integer
Returns the number of Changes in the Release.
-
#contributors ⇒ Array<String>
Retrieves a unique, sorted list of contributor logins for the Release.
-
#initialize(code:, date: nil, hash: nil, memo: nil, changes: []) ⇒ Release
constructor
Initializes a new Release object.
-
#tag_stats ⇒ Hash{String => Integer}
Calculates a hash with the count of each tag used in the Release.
-
#to_h ⇒ Hash
Converts the Release metadata to a hash representation.
Constructor Details
#initialize(code:, date: nil, hash: nil, memo: nil, changes: []) ⇒ Release
Initializes a new Release object.
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
#changes ⇒ Object (readonly)
Returns the value of attribute changes.
10 11 12 |
# File 'lib/releasehx/rhyml/release.rb', line 10 def changes @changes end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
10 11 12 |
# File 'lib/releasehx/rhyml/release.rb', line 10 def code @code end |
#date ⇒ Object (readonly)
Returns the value of attribute date.
10 11 12 |
# File 'lib/releasehx/rhyml/release.rb', line 10 def date @date end |
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
10 11 12 |
# File 'lib/releasehx/rhyml/release.rb', line 10 def hash @hash end |
#memo ⇒ Object (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.
38 39 40 41 |
# File 'lib/releasehx/rhyml/release.rb', line 38 def add_change change attach_release(change) @changes << change end |
#change_count ⇒ Integer
Returns the number of Changes in the Release.
46 47 48 |
# File 'lib/releasehx/rhyml/release.rb', line 46 def change_count changes.size end |
#contributors ⇒ Array<String>
Retrieves a unique, sorted list of contributor logins for the Release.
53 54 55 |
# File 'lib/releasehx/rhyml/release.rb', line 53 def contributors changes.map(&:lead).compact.uniq end |
#tag_stats ⇒ Hash{String => Integer}
Calculates a hash with the count of each tag used in the Release.
61 62 63 |
# File 'lib/releasehx/rhyml/release.rb', line 61 def tag_stats changes.compact.flat_map { |c| c. || [] }.tally end |
#to_h ⇒ Hash
Note:
Converts the Release metadata to a hash representation.
This method excludes the Changes array from the output.
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 |