Sha256: fdce6088ef66e43f77cbd1184d636c41908f84b42534e6ba5157213400732bd8

Contents?: true

Size: 1.15 KB

Versions: 4

Compression:

Stored size: 1.15 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 ||= NullVersion.new
        end
      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

      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

4 entries across 4 versions & 1 rubygems

Version Path
convenient_service-0.5.0 lib/convenient_service/support/version.rb
convenient_service-0.4.0 lib/convenient_service/support/version.rb
convenient_service-0.3.1 lib/convenient_service/support/version.rb
convenient_service-0.3.0 lib/convenient_service/support/version.rb