Sha256: 0eddf5e18da3fd27eed32cbebd644159e352633c0e6f49448a0143d47a509942

Contents?: true

Size: 1.29 KB

Versions: 14

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

require_relative "version/null_version"

module ConvenientService
  module Support
    class Version
      include ::Comparable

      undef_method :between?

      undef_method :clamp

      ##
      # @param value [String]
      # @return [void]
      #
      def initialize(value)
        @value = value
      end

      class << self
        ##
        # @return [ConvenientService::Support::Version::NullVersion]
        #
        def null_version
          @null_version ||= Support::Version::NullVersion.new
        end
      end

      ##
      # @return [Boolean]
      #
      def null_version?
        false
      end

      ##
      # @return [Gem::Version, nil]
      #
      def gem_version
        cast_gem_version(value)
      end

      ##
      # @param other [Object] Can be any type.
      # @return [Boolean, nil]
      #
      def <=>(other)
        gem_version <=> cast_gem_version(other)
      end

      ##
      # @return [String]
      #
      def to_s
        gem_version.to_s
      end

      private

      ##
      # @return [String]
      #
      attr_reader :value

      ##
      # @return [Gem::Version, nil]
      #
      def cast_gem_version(value)
        ::Gem::Version.create(value.to_s) if ::Gem::Version.correct?(value.to_s)
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
convenient_service-0.18.0 lib/convenient_service/support/version.rb
convenient_service-0.17.0 lib/convenient_service/support/version.rb
convenient_service-0.16.0 lib/convenient_service/support/version.rb
convenient_service-0.15.0 lib/convenient_service/support/version.rb
convenient_service-0.14.0 lib/convenient_service/support/version.rb
convenient_service-0.13.0 lib/convenient_service/support/version.rb
convenient_service-0.12.0 lib/convenient_service/support/version.rb
convenient_service-0.11.0 lib/convenient_service/support/version.rb
convenient_service-0.10.1 lib/convenient_service/support/version.rb
convenient_service-0.10.0 lib/convenient_service/support/version.rb
convenient_service-0.9.0 lib/convenient_service/support/version.rb
convenient_service-0.8.0 lib/convenient_service/support/version.rb
convenient_service-0.7.0 lib/convenient_service/support/version.rb
convenient_service-0.6.0 lib/convenient_service/support/version.rb