Sha256: bec16bdd99dd9bd1fb37e67d21bea30baf99c5898791a43d821444e8135a45c5

Contents?: true

Size: 1.83 KB

Versions: 119

Compression:

Stored size: 1.83 KB

Contents

module Fastlane
  module Helper
    class PodspecHelper
      attr_accessor :path
      attr_accessor :podspec_content
      attr_accessor :version_regex
      attr_accessor :version_match
      attr_accessor :version_value

      def initialize(path = nil)
        version_var_name = 'version'
        @version_regex = /^(?<begin>[^#]*#{version_var_name}\s*=\s*['"])(?<value>(?<major>[0-9]+)(\.(?<minor>[0-9]+))?(\.(?<patch>[0-9]+))?)(?<end>['"])/i

        return unless (path || '').length > 0
        UI.user_error!("Could not find podspec file at path '#{path}'") unless File.exist?(path)

        @path = File.expand_path(path)
        podspec_content = File.read(path)

        parse(podspec_content)
      end

      def parse(podspec_content)
        @podspec_content = podspec_content
        @version_match = @version_regex.match(@podspec_content)
        UI.user_error!("Could not find version in podspec content '#{@podspec_content}'") if @version_match.nil?
        @version_value = @version_match[:value]
      end

      def bump_version(bump_type)
        major = version_match[:major].to_i
        minor = version_match[:minor].to_i || 0
        patch = version_match[:patch].to_i || 0

        case bump_type
        when 'patch'
          patch += 1
        when 'minor'
          minor += 1
          patch = 0
        when 'major'
          major += 1
          minor = 0
          patch = 0
        end

        @version_value = "#{major}.#{minor}.#{patch}"
      end

      def update_podspec(version = nil)
        new_version = version || @version_value
        updated_podspec_content = @podspec_content.gsub(@version_regex, "#{@version_match[:begin]}#{new_version}#{@version_match[:end]}")

        File.open(@path, "w") { |file| file.puts updated_podspec_content } unless Helper.test?

        updated_podspec_content
      end
    end
  end
end

Version data entries

119 entries across 119 versions & 1 rubygems

Version Path
fastlane-2.21.0.beta.20170320010043 fastlane/lib/fastlane/helper/podspec_helper.rb
fastlane-2.21.0.beta.20170319010027 fastlane/lib/fastlane/helper/podspec_helper.rb
fastlane-2.21.0.beta.20170318010107 fastlane/lib/fastlane/helper/podspec_helper.rb
fastlane-2.21.0.beta.20170317010039 fastlane/lib/fastlane/helper/podspec_helper.rb
fastlane-2.21.0.beta.20170316010039 fastlane/lib/fastlane/helper/podspec_helper.rb
fastlane-2.20.0 fastlane/lib/fastlane/helper/podspec_helper.rb
fastlane-2.20.0.beta.20170315010053 fastlane/lib/fastlane/helper/podspec_helper.rb
fastlane-2.20.0.beta.20170314010029 fastlane/lib/fastlane/helper/podspec_helper.rb
fastlane-2.20.0.beta.20170313010048 fastlane/lib/fastlane/helper/podspec_helper.rb
fastlane-2.20.0.beta.20170312010035 fastlane/lib/fastlane/helper/podspec_helper.rb
fastlane-2.20.0.beta.20170311010030 fastlane/lib/fastlane/helper/podspec_helper.rb
fastlane-2.20.0.beta.20170310010058 fastlane/lib/fastlane/helper/podspec_helper.rb
fastlane-2.20.0.beta.20170309010049 fastlane/lib/fastlane/helper/podspec_helper.rb
fastlane-2.20.0.beta.20170308010036 fastlane/lib/fastlane/helper/podspec_helper.rb
fastlane-2.19.3 fastlane/lib/fastlane/helper/podspec_helper.rb
fastlane-2.20.0.beta.20170307010029 fastlane/lib/fastlane/helper/podspec_helper.rb
fastlane-2.19.2 fastlane/lib/fastlane/helper/podspec_helper.rb
fastlane-2.20.0.beta.20170306010752 fastlane/lib/fastlane/helper/podspec_helper.rb
fastlane-2.20.0.beta.20170305010057 fastlane/lib/fastlane/helper/podspec_helper.rb
fastlane-2.20.0.beta.20170304010023 fastlane/lib/fastlane/helper/podspec_helper.rb