Sha256: d9286a6f7aa8460ded0a097ab1b4c0b99378bdb68ffcafe3c083fd276a6134d6

Contents?: true

Size: 1.11 KB

Versions: 5

Compression:

Stored size: 1.11 KB

Contents

require "magellan/cli"

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

5 entries across 5 versions & 1 rubygems

Version Path
magellan-cli-0.5.2 lib/magellan/cli/gem_update.rb
magellan-cli-0.5.1 lib/magellan/cli/gem_update.rb
magellan-cli-0.5.0 lib/magellan/cli/gem_update.rb
magellan-cli-0.4.4 lib/magellan/cli/gem_update.rb
magellan-cli-0.4.3 lib/magellan/cli/gem_update.rb