Sha256: e4e20174cae52e771781aa38379a0b979e1c5e2e17057f43ddb62bbb7b0862fa

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 KB

Contents

module Rake::Funnel::Support
  class Version
    class << self
      def parse(context)
        {
          assembly_version: assembly_version(context),
          assembly_file_version: assembly_file_version(context),
          assembly_informational_version: assembly_informational_version(context)
        }
      end

      private
      def default_version(context)
        context[:version] || '0'
      end

      def assembly_version(context)
        strip_trailing_non_numeric(default_version(context))
      end

      def assembly_file_version(context)
        numeric_build_number = strip_leading_non_numeric(context[:build_number])

        [
          assembly_version(context),
          numeric_build_number
        ].compact.join('.')
      end

      def assembly_informational_version(context)
        build_number = context[:build_number]
        join_using = '.'
        join_using = '' if build_number =~ /^\D/

        prefix = [default_version(context), build_number].compact.join(join_using)
        sha = context[:sha]

        [prefix, sha].compact.join('-')
      end

      def strip_trailing_non_numeric(str)
        return nil if str.nil?
        str.gsub(/[^\d\.].*/, '')
      end

      def strip_leading_non_numeric(str)
        return nil if str.nil?
        str = str.gsub(/[^\d\.]/, '')

        return nil if str.empty?
        str
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rake-funnel-0.0.6.pre lib/rake/funnel/support/version.rb