Sha256: 3a6ea32a093e4043f3f66a17695171ed451ecd2beca38ef4b285fb96952d0cf4

Contents?: true

Size: 1.05 KB

Versions: 44

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module CKEditor5
  module Rails
    class Semver
      SEMVER_PATTERN = /\A\d+\.\d+\.\d+\z/

      attr_reader :major, :minor, :patch

      include Comparable

      def initialize(version_string)
        validate!(version_string)
        @major, @minor, @patch = version_string.split('.').map(&:to_i)
      end

      def <=>(other)
        return nil unless other.is_a?(Semver)

        [major, minor, patch] <=> [other.major, other.minor, other.patch]
      end

      def safe_update?(other_version)
        other = self.class.new(other_version)

        return false if other.major != major
        return true if other.minor > minor
        return true if other.minor == minor && other.patch > patch

        false
      end

      def version
        "#{major}.#{minor}.#{patch}"
      end

      alias to_s :version

      private

      def validate!(version_string)
        return if version_string.is_a?(String) && version_string.match?(SEMVER_PATTERN)

        raise ArgumentError, 'invalid version format'
      end
    end
  end
end

Version data entries

44 entries across 44 versions & 2 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/ckeditor5-1.24.9/lib/ckeditor5/rails/semver.rb
ckeditor5-1.24.9 lib/ckeditor5/rails/semver.rb
ckeditor5-1.24.8 lib/ckeditor5/rails/semver.rb
ckeditor5-1.24.6 lib/ckeditor5/rails/semver.rb
ckeditor5-1.24.5 lib/ckeditor5/rails/semver.rb
ckeditor5-1.24.4 lib/ckeditor5/rails/semver.rb
ckeditor5-1.24.3 lib/ckeditor5/rails/semver.rb
ckeditor5-1.24.2 lib/ckeditor5/rails/semver.rb
ckeditor5-1.24.1 lib/ckeditor5/rails/semver.rb
ckeditor5-1.24.0 lib/ckeditor5/rails/semver.rb
ckeditor5-1.23.5 lib/ckeditor5/rails/semver.rb
ckeditor5-1.23.4 lib/ckeditor5/rails/semver.rb
ckeditor5-1.23.3 lib/ckeditor5/rails/semver.rb
ckeditor5-1.23.2 lib/ckeditor5/rails/semver.rb
ckeditor5-1.23.1 lib/ckeditor5/rails/semver.rb
ckeditor5-1.23.0 lib/ckeditor5/rails/semver.rb
ckeditor5-1.22.0 lib/ckeditor5/rails/semver.rb
ckeditor5-1.21.0 lib/ckeditor5/rails/semver.rb
ckeditor5-1.20.1 lib/ckeditor5/rails/semver.rb
ckeditor5-1.20.0 lib/ckeditor5/rails/semver.rb