Sha256: 821ca01f70eedc34d83bbadf8938c30287f1aab523a101efd9f3076ad20d67e0

Contents?: true

Size: 1.15 KB

Versions: 37

Compression:

Stored size: 1.15 KB

Contents

module CapistranoMulticonfigParallel
  # helper used to determine gem versions
  module GemHelper
    module_function

    def find_loaded_gem(name, property = nil)
      gem_spec = Gem.loaded_specs.values.find { |repo| repo.name == name }
      gem_spec.present? && property.present? ? gem_spec.send(property).to_s : gem_spec
    end

    def find_loaded_gem_property(gem_name, property = 'version')
      find_loaded_gem(gem_name, property)
    end

    def fetch_gem_version(gem_name)
      version = find_loaded_gem_property(gem_name)
      version.blank? ? nil : get_parsed_version(version)
    end

    def get_parsed_version(version)
      return 0 if version.blank?
      version = version.to_s.split('.')
      version = format_gem_version(version)
      version.join('.').to_f
    end

    def format_gem_version(version)
      return version if version.size <= 2
      version.pop until version.size == 2
      version
    end

    def verify_gem_version(gem_version, version, options = {})
      options.stringify_keys!
      version = get_parsed_version(version)
      get_parsed_version(gem_version).send(options.fetch('operator', '<='), version)
    end

  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
capistrano_multiconfig_parallel-2.8.1 lib/capistrano_multiconfig_parallel/helpers/gem_helper.rb
capistrano_multiconfig_parallel-2.8.0 lib/capistrano_multiconfig_parallel/helpers/gem_helper.rb
capistrano_multiconfig_parallel-2.7.1 lib/capistrano_multiconfig_parallel/helpers/gem_helper.rb
capistrano_multiconfig_parallel-2.7.0 lib/capistrano_multiconfig_parallel/helpers/gem_helper.rb
capistrano_multiconfig_parallel-2.6.2 lib/capistrano_multiconfig_parallel/helpers/gem_helper.rb
capistrano_multiconfig_parallel-2.6.1 lib/capistrano_multiconfig_parallel/helpers/gem_helper.rb
capistrano_multiconfig_parallel-2.6.0 lib/capistrano_multiconfig_parallel/helpers/gem_helper.rb
capistrano_multiconfig_parallel-2.5.0 lib/capistrano_multiconfig_parallel/helpers/gem_helper.rb
capistrano_multiconfig_parallel-2.4.0 lib/capistrano_multiconfig_parallel/helpers/gem_helper.rb
capistrano_multiconfig_parallel-2.3.5 lib/capistrano_multiconfig_parallel/helpers/gem_helper.rb
capistrano_multiconfig_parallel-2.3.4 lib/capistrano_multiconfig_parallel/helpers/gem_helper.rb
capistrano_multiconfig_parallel-2.3.3 lib/capistrano_multiconfig_parallel/helpers/gem_helper.rb
capistrano_multiconfig_parallel-2.3.2 lib/capistrano_multiconfig_parallel/helpers/gem_helper.rb
capistrano_multiconfig_parallel-2.3.1 lib/capistrano_multiconfig_parallel/helpers/gem_helper.rb
capistrano_multiconfig_parallel-2.3.0 lib/capistrano_multiconfig_parallel/helpers/gem_helper.rb
capistrano_multiconfig_parallel-2.2.0 lib/capistrano_multiconfig_parallel/helpers/gem_helper.rb
capistrano_multiconfig_parallel-2.1.1 lib/capistrano_multiconfig_parallel/helpers/gem_helper.rb
capistrano_multiconfig_parallel-2.1.0 lib/capistrano_multiconfig_parallel/helpers/gem_helper.rb
capistrano_multiconfig_parallel-2.0.9 lib/capistrano_multiconfig_parallel/helpers/gem_helper.rb
capistrano_multiconfig_parallel-2.0.8 lib/capistrano_multiconfig_parallel/helpers/gem_helper.rb