Class: Fastlane::Wpmreleasetoolkit::Versioning::IOSVersionFile

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

Overview

The ‘IOSVersionFile` class takes in an .xcconfig file path and reads/writes values to/from the file.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xcconfig_path:) ⇒ IOSVersionFile

Initializes a new instance of IOSVersionFile with the specified .xcconfig file path.

Parameters:

  • xcconfig_path (String)

    The path to the .xcconfig file.



14
15
16
17
18
# File 'lib/fastlane/plugin/wpmreleasetoolkit/versioning/files/ios_version_file.rb', line 14

def initialize(xcconfig_path:)
  UI.user_error!(".xcconfig file not found at this path: #{xcconfig_path}") unless File.exist?(xcconfig_path)

  @xcconfig_path = xcconfig_path
end

Instance Attribute Details

#xcconfig_pathObject (readonly)

Returns the value of attribute xcconfig_path.



8
9
10
# File 'lib/fastlane/plugin/wpmreleasetoolkit/versioning/files/ios_version_file.rb', line 8

def xcconfig_path
  @xcconfig_path
end

Instance Method Details

#read_build_code(attribute_name:) ⇒ String

Reads the build code from the .xcconfig file and returns it String.

Some apps store the build code in the VERSION_LONG attribute, while others store it in the BUILD_NUMBER attribute.

Parameters:

  • attribute_name (String)

    The name of the attribute to read.

Returns:

  • (String)

    The build code.



37
38
39
40
41
42
# File 'lib/fastlane/plugin/wpmreleasetoolkit/versioning/files/ios_version_file.rb', line 37

def read_build_code(attribute_name:)
  UI.user_error!('attribute_name must be `VERSION_LONG` or `BUILD_NUMBER`') unless attribute_name.eql?('VERSION_LONG') || attribute_name.eql?('BUILD_NUMBER')

  config = Xcodeproj::Config.new(xcconfig_path)
  config.attributes[attribute_name]
end

#read_release_versionString

Reads the release version from the .xcconfig file and returns it as a String.

Returns:

  • (String)

    The release version.



24
25
26
27
# File 'lib/fastlane/plugin/wpmreleasetoolkit/versioning/files/ios_version_file.rb', line 24

def read_release_version
  config = Xcodeproj::Config.new(xcconfig_path)
  config.attributes['VERSION_SHORT']
end

#write(version_short: nil, version_long: nil, build_number: nil) ⇒ Object

Writes the provided version numbers to the .xcconfig file.

version_long is optional because there are times when it won’t be updated, such as a new beta build. version_short is optional because some apps (such as Day One iOS/Mac or Simplenote Mac) don’t use it. build_number is optional because some apps (such as WP/JP iOS or WCiOS) don’t use it.

Parameters:

  • version_short (String, nil) (defaults to: nil)

    The short version string (optional).

  • version_long (String, nil) (defaults to: nil)

    The long version string (optional).

  • build_number (String, nil) (defaults to: nil)

    The build number (optional).



54
55
56
57
58
59
60
# File 'lib/fastlane/plugin/wpmreleasetoolkit/versioning/files/ios_version_file.rb', line 54

def write(version_short: nil, version_long: nil, build_number: nil)
  config = Xcodeproj::Config.new(xcconfig_path)
  config.attributes['VERSION_SHORT'] = version_short.to_s unless version_short.nil?
  config.attributes['VERSION_LONG'] = version_long.to_s unless version_long.nil?
  config.attributes['BUILD_NUMBER'] = build_number.to_s unless build_number.nil?
  config.save_as(Pathname.new(xcconfig_path))
end