Class: Fastlane::Wpmreleasetoolkit::Versioning::DerivedBuildCodeFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/wpmreleasetoolkit/versioning/formatters/derived_build_code_formatter.rb

Overview

The ‘DerivedBuildCodeFormatter` class is a specialized build code formatter for derived build codes. It takes in an AppVersion object and derives a build code from it.

Instance Method Summary collapse

Constructor Details

#initialize(prefix: nil, major_digits: 2, minor_digits: 2, patch_digits: 2, build_digits: 2) ⇒ DerivedBuildCodeFormatter

Initialize the formatter with configurable prefix and digit counts.

Parameters:

  • prefix (String) (defaults to: nil)

    The prefix to use for the build code. Must be a single digit (0-9), or empty string / nil.

  • major_digits (Integer) (defaults to: 2)

    Number of digits for major version. Must be between 1–3. Defaults to 2.

  • minor_digits (Integer) (defaults to: 2)

    Number of digits for minor version. Must be between 1–3. Defaults to 2.

  • patch_digits (Integer) (defaults to: 2)

    Number of digits for patch version. Must be between 1–3. Defaults to 2.

  • build_digits (Integer) (defaults to: 2)

    Number of digits for build number. Must be between 1–3. Defaults to 2.



22
23
24
25
26
27
28
29
# File 'lib/fastlane/plugin/wpmreleasetoolkit/versioning/formatters/derived_build_code_formatter.rb', line 22

def initialize(prefix: nil, major_digits: 2, minor_digits: 2, patch_digits: 2, build_digits: 2)
  validate_prefix!(prefix)
  @prefix = prefix.to_s

  @digit_counts = [major_digits, minor_digits, patch_digits, build_digits]
  @digit_counts.each { |d| validate_digit_count!(d) }
  validate_total_digits!(@digit_counts)
end

Instance Method Details

#build_code(_build_code = nil, version:) ⇒ String

Calculate the next derived build code.

This method derives a new build code from the given AppVersion object by concatenating the configured prefix, the major version, the minor version, the patch version, and the build number with configurable digit counts.

to have a consistent signature with other build code formatters.

Parameters:

  • version (AppVersion)

    The AppVersion object to derive the next build code from.

  • build_code (BuildCode)

    A BuildCode object. This parameter is ignored but is included

Returns:

  • (String)

    The formatted build code string.



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/fastlane/plugin/wpmreleasetoolkit/versioning/formatters/derived_build_code_formatter.rb', line 43

def build_code(_build_code = nil, version:)
  formatted_components = version.components.zip(@digit_counts).map do |value, width|
    comp = value.to_s.rjust(width, '0')
    if comp.length > width
      UI.user_error!("Version component value (#{value}) exceeds maximum allowed width of #{width} characters. " \
                     "Consider increasing the corresponding `*_digits` parameter of your `#{self.class.name}`")
    end
    comp
  end
  [@prefix, *formatted_components].join.gsub(/^0+/, '')
end