Sha256: 4a2e42bc633b4d58c63efbe860a148224182cb71963a6f9c28c14262c63ad445

Contents?: true

Size: 1.13 KB

Versions: 34

Compression:

Stored size: 1.13 KB

Contents

require "magellan/cli"

require 'time'
require 'thor'
require 'active_support/core_ext/string/inflections'

module Magellan
  module Cli

    module GemUpdate
      LAST_UPDATE_SEARCHED_AT = "last_update_searched_at".freeze
      UPDATE_SEARCH_INTERVAL = 1 * 24 * 60 * 60 # 1 day

      class << self

        def search
          t = FileAccess.load_selections[LAST_UPDATE_SEARCHED_AT]
          return nil if t && (Time.now < Time.parse(t) + UPDATE_SEARCH_INTERVAL)
          name = "magellan-cli"
          version = `gem search -r #{name} -q --no-details --versions`.scan(/\((.*)\)/).flatten.first
          FileAccess.update_selections({LAST_UPDATE_SEARCHED_AT => Time.now.to_s})
          if version
            curr = Gem::Version.new(Magellan::Cli::VERSION)
            last = Gem::Version.new(version)
            if last > curr
              yield(name, version) if block_given?
              return version
            else
              # puts "#{curr} is newer than equal #{last}"
            end
          else
            # puts "no gem version found for #{name}"
          end
          return nil
        end

      end
    end

  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
magellan-cli-0.11.1 lib/magellan/cli/gem_update.rb
magellan-cli-0.11.0 lib/magellan/cli/gem_update.rb
magellan-cli-0.10.0 lib/magellan/cli/gem_update.rb
magellan-cli-0.9.1 lib/magellan/cli/gem_update.rb
magellan-cli-0.9.0 lib/magellan/cli/gem_update.rb
magellan-cli-0.8.3 lib/magellan/cli/gem_update.rb
magellan-cli-0.8.2 lib/magellan/cli/gem_update.rb
magellan-cli-0.8.1 lib/magellan/cli/gem_update.rb
magellan-cli-0.8.0 lib/magellan/cli/gem_update.rb
magellan-cli-0.7.11 lib/magellan/cli/gem_update.rb
magellan-cli-0.7.10 lib/magellan/cli/gem_update.rb
magellan-cli-0.7.9 lib/magellan/cli/gem_update.rb
magellan-cli-0.7.8 lib/magellan/cli/gem_update.rb
magellan-cli-0.7.7 lib/magellan/cli/gem_update.rb
magellan-cli-0.7.6 lib/magellan/cli/gem_update.rb
magellan-cli-0.7.5 lib/magellan/cli/gem_update.rb
magellan-cli-0.7.4 lib/magellan/cli/gem_update.rb
magellan-cli-0.7.3 lib/magellan/cli/gem_update.rb
magellan-cli-0.7.2 lib/magellan/cli/gem_update.rb
magellan-cli-0.7.1 lib/magellan/cli/gem_update.rb