Class: Fastlane::Wpmreleasetoolkit::Versioning::DerivedBuildCodeFormatter
- Inherits:
-
Object
- Object
- Fastlane::Wpmreleasetoolkit::Versioning::DerivedBuildCodeFormatter
- 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
-
#build_code(_build_code = nil, version:) ⇒ String
Calculate the next derived build code.
-
#initialize(prefix: nil, major_digits: 2, minor_digits: 2, patch_digits: 2, build_digits: 2) ⇒ DerivedBuildCodeFormatter
constructor
Initialize the formatter with configurable prefix and digit counts.
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.
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.
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 |