Sha256: 67e7e98c4fdcf15ce55d043499554b3ddb08bf53bd928de61c87e7c2eca85f46
Contents?: true
Size: 1.93 KB
Versions: 3
Compression:
Stored size: 1.93 KB
Contents
# -*- coding: utf-8 -*- require 'bundler' require 'colored' require 'json' require 'open-uri' require 'slop' require 'appraiser/version' module Appraiser extend self RUBY_GEMS_URL = 'http://rubygems.org/api/v1/gems/%s.json' LINE = '-' * 60 def execute(*args) opts = Slop.parse do on :g, :group, 'Group', true end group = opts.group? ? opts[:group].to_sym : :default dependencies_for(group).each do |dependency| json = load_json(dependency.name) if json.empty? puts dependency.name.green puts "Source : #{dependency.source.to_s.cyan.underline}" else name = json['name'] authors = json['authors'] downloads = number_with_delimiter(json['downloads']) project_uri = json['project_uri'] doc_uri = json['documentation_uri'] src_uri = json['source_code_uri'] info = json['info'].split("\n").first.strip puts "#{name.green} (by #{authors})" puts "Downloads: #{downloads.blue}" puts "Project : #{project_uri.cyan.underline}" if project_uri puts "Document : #{doc_uri.cyan.underline}" if doc_uri puts "Source : #{src_uri.cyan.underline}" if src_uri puts info end puts LINE end end private # @param [String] gem_name # @return [Hash] def load_json(gem_name) JSON.parse(open(RUBY_GEMS_URL % gem_name).read) rescue OpenURI::HTTPError => e {} end # @param [Symbol] group # @return [Array<Bundler::Dependency>] def dependencies_for(group) Bundler.definition.dependencies.select{ |i| i.groups.include? group } end # @param [Integer] number # @param [String] delimiter # @param [String] separator # @return [String] def number_with_delimiter(number, delimiter = ',', separator = '.') parts = number.to_s.split('.') parts[0].gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{delimiter}") parts.join separator rescue number.to_s end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
appraiser-0.1.4 | lib/appraiser.rb |
appraiser-0.1.3 | lib/appraiser.rb |
appraiser-0.1.2 | lib/appraiser.rb |