Sha256: 257b1178c69eeab8b8689c3f6afad90200bdcee3108c661f770bc72a8272e846
Contents?: true
Size: 1.48 KB
Versions: 1
Compression:
Stored size: 1.48 KB
Contents
#!/usr/bin/env ruby require 'open-uri' require 'yaml' require_relative '../lib/rg_stats/statistic' user_name = ARGV[0] class PersistDataBetweenSessions STORAGE_NAME = "/tmp/ruby_gems_sync.yaml" def self.load File.exists?(STORAGE_NAME) ? File.open(STORAGE_NAME, "r") { |file| YAML.load(file) } : [] end def self.save(list) File.open(STORAGE_NAME, "w") {|file| file.puts(list.to_yaml) } end end if user_name.nil? puts "" puts "Type username on RubyGems as argument: rg_stats user_name" puts "" exit end url = "https://rubygems.org/api/v1/owners/#{user_name}/gems.json" begin data_as_json = open(url) rescue SocketError => e puts "It seems connection is not available. (#{e.message})" exit rescue OpenURI::HTTPError => e puts "User #{user_name} has not been found. (#{e.message})" exit end old_data = PersistDataBetweenSessions.load old_map = {} old_data.each do |old_gem_info| old_map[old_gem_info[0]] = old_gem_info[1] end stat = Statistic.new stat.load data_as_json puts "" puts "\e[32m#{user_name}\e[0m" puts "-" *(stat.max_gem_name_size + 30) stat.gem_infos.each do |gem_info| broj_izmjena = gem_info[1] - (old_map[gem_info[0]].nil? ? 0 : old_map[gem_info[0]]) diff_from_last_time = broj_izmjena == 0 ? "" : " (+\e[32m#{broj_izmjena}\e[0m)" puts "%-#{stat.max_gem_name_size + 1}s=> %6d %6s" % [ gem_info[0] , gem_info[1], diff_from_last_time ] puts "-" *(stat.max_gem_name_size + 30) end puts "" PersistDataBetweenSessions.save(stat.gem_infos)
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rg_stats-1.0.2 | bin/rg_stats |