appraiser-0.2.0/0000755000175000017500000000000012646023310012072 5ustar aleealeeappraiser-0.2.0/Rakefile0000644000175000017500000000026312646023310013540 0ustar aleealeerequire 'bundler' Bundler::GemHelper.install_tasks require 'rspec/core/rake_task' RSpec::Core::RakeTask.new do |t| t.pattern = 'spec/**/*_spec.rb' end task :default => :spec appraiser-0.2.0/appraiser.gemspec0000644000175000017500000000235412646023310015431 0ustar aleealee# -*- encoding: utf-8 -*- $:.push File.expand_path("../lib", __FILE__) require "appraiser/version" Gem::Specification.new do |s| s.name = "appraiser" s.version = Appraiser::VERSION s.platform = Gem::Platform::RUBY s.authors = ["Junya Ogura"] s.email = ["junyaogura@gmail.com"] s.homepage = "https://github.com/juno/appraiser" s.licenses = ["MIT"] s.summary = %q{`appraiser` is a simple rubygems subcommand for Gemfile.} s.description = %q{`appraiser` is a rubygems subcommand which displays gem information in `./Gemfile`.} s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } s.require_paths = ["lib"] s.post_install_message = %q{ appraiser installed as a rubygems subcommand. (basic) $ gem appraiser (shorthand) $ gem a ("group" option) $ gem a -g test } s.add_dependency('bundler', ['~> 1.3']) s.add_dependency('colored', ['~> 1.2']) s.add_dependency('json') s.add_development_dependency('rake', ['~> 10.0']) s.add_development_dependency('rspec', ['~> 2.13']) s.add_development_dependency('webmock', ['~> 1.11']) end appraiser-0.2.0/spec/0000755000175000017500000000000012646023310013024 5ustar aleealeeappraiser-0.2.0/spec/spec_helper.rb0000644000175000017500000000063312646023310015644 0ustar aleealee# -*- coding: utf-8 -*- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) $LOAD_PATH.unshift(File.dirname(__FILE__)) require 'rspec' require 'webmock/rspec' require 'rubygems/commands/appraiser_command' Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f} RSpec.configure do |config| config.expect_with :rspec do |c| c.syntax = :expect # disables `should` end end appraiser-0.2.0/spec/appraiser_spec.rb0000644000175000017500000002026512646023310016356 0ustar aleealee# -*- coding: utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/spec_helper') describe Gem::Commands::AppraiserCommand do before do @rails_json = <<-EOD {"dependencies":{"runtime":[{"name":"actionmailer","requirements":"= 3.0.9"},{"name":"actionpack","requirements":"= 3.0.9"},{"name":"activerecord","requirements":"= 3.0.9"},{"name":"activeresource","requirements":"= 3.0.9"},{"name":"activesupport","requirements":"= 3.0.9"},{"name":"bundler","requirements":"~> 1.0"},{"name":"railties","requirements":"= 3.0.9"}],"development":[]},"name":"rails","downloads":4977205,"info":"Ruby on Rails is a full-stack web framework optimized for programmer happiness and sustainable productivity. It encourages beautiful code by favoring convention over configuration.","version_downloads":306973,"version":"3.0.9","homepage_uri":"http://www.rubyonrails.org","bug_tracker_uri":"http://rails.lighthouseapp.com/projects/8994-ruby-on-rails","source_code_uri":"http://github.com/rails/rails","gem_uri":"http://rubygems.org/gems/rails-3.0.9.gem","project_uri":"http://rubygems.org/gems/rails","authors":"David Heinemeier Hansson","mailing_list_uri":"http://groups.google.com/group/rubyonrails-talk","documentation_uri":"http://api.rubyonrails.org","wiki_uri":"http://wiki.rubyonrails.org"} EOD @empty_json = '{}' end describe "Constants" do describe "RUBY_GEMS_URL" do subject { Gem::Commands::AppraiserCommand::RUBY_GEMS_URL } it { should eq('http://rubygems.org/api/v1/gems/%s.json') } end describe "LINE" do subject { Gem::Commands::AppraiserCommand::LINE } it { should eq('-' * 60) } end end # Instance methods describe "#usage" do let(:command) { Gem::Commands::AppraiserCommand.new } subject { command.usage } it { should eq('gem appraiser [-g group]') } end describe "#execute" do let(:command) { Gem::Commands::AppraiserCommand.new } it "call #process with STDOUT as output" do command.should_receive(:process).with($stdout) command.execute end end # private methods describe "#process(output)" do let(:command) { Gem::Commands::AppraiserCommand.new } let(:output) { stub(IO).as_null_object } context "response body is not empty json" do before do dependencies = [] dependencies << stub(Bundler::Dependency, :groups => [:default], :name => 'rails') dependencies << stub(Bundler::Dependency, :groups => [:test], :name => 'rspec') Bundler.stub_chain(:definition, :dependencies) { dependencies } end it "retrieves :default group dependency json from RubyGems API" do stub_request(:get, 'http://rubygems.org/api/v1/gems/rails.json'). to_return(:status => 200, :body => @rails_json) command.send(:process, output) expect(a_request(:get, 'http://rubygems.org/api/v1/gems/rails.json')) \ .to have_been_made.once end it "not retrieves :test group dependency json from RubyGems API" do stub_request(:get, 'http://rubygems.org/api/v1/gems/rails.json'). to_return(:status => 200, :body => @rails_json) command.send(:process, output) expect(a_request(:get, 'http://rubygems.org/api/v1/gems/rspec.json')) \ .not_to have_been_made end end context "response body is empty json" do before do @dependency = stub(Bundler::Dependency, :groups => [:default], :name => 'rails', :source => 'git://github.com/tenderlove/nokogiri.git') Bundler.stub_chain(:definition, :dependencies) { [@dependency] } stub_request(:get, 'http://rubygems.org/api/v1/gems/rails.json'). to_return(:status => 200, :body => @empty_json) end it "not raises exception" do expect { command.send(:process, output) }.to_not raise_error end it "puts dependency source" do @dependency.should_receive(:source) { 'git://github.com/tenderlove/nokogiri.git' } command.send(:process, output) end end end describe "#load_json(gem_name)" do let(:command) { Gem::Commands::AppraiserCommand.new } let(:gem_name) { 'rails' } context "open() raises OpenURI::HTTPError exception" do before do stub_request(:get, 'http://rubygems.org/api/v1/gems/rails.json'). to_raise(OpenURI::HTTPError.new('error', stub(StringIO))) end subject { command.send(:load_json, gem_name) } it { should be_kind_of(Hash) } it { should be_empty } end context "open() returns JSON response" do before do stub_request(:get, 'http://rubygems.org/api/v1/gems/rails.json'). to_return(:status => 200, :body => @rails_json) @result = command.send(:load_json, gem_name) end it "have key 'name'" do expect(@result).to have_key('name') expect(@result['name']).to eq('rails') end it "have key 'authors'" do expect(@result).to have_key('authors') expect(@result['authors']).to eq('David Heinemeier Hansson') end it "have key 'downloads'" do expect(@result).to have_key('downloads') expect(@result['downloads']).to eq(4977205) end it "have key 'project_uri'" do expect(@result).to have_key('project_uri') expect(@result['project_uri']).to eq('http://rubygems.org/gems/rails') end it "have key 'documentation_uri'" do expect(@result).to have_key('documentation_uri') expect(@result['documentation_uri']).to eq('http://api.rubyonrails.org') end it "have key 'source_code_uri'" do expect(@result).to have_key('source_code_uri') expect(@result['source_code_uri']).to eq('http://github.com/rails/rails') end it "have key 'info'" do expect(@result).to have_key('info') expect(@result['info']) \ .to eq("Ruby on Rails is a full-stack web framework optimized for programmer happiness and sustainable productivity. It encourages beautiful code by favoring convention over configuration.") end end end describe "#dependencies_for(group)" do let(:command) { Gem::Commands::AppraiserCommand.new } let(:group) { :development } it "should call Bundler.definition.dependencies.select" do dependencies = [] dependencies << stub(Bundler::Dependency, :groups => [:default]) dependencies << stub(Bundler::Dependency, :groups => [:development]) dependencies << stub(Bundler::Dependency, :groups => [:development, :test]) Bundler.stub_chain(:definition, :dependencies) { dependencies } result = command.send(:dependencies_for, group) expect(result).to have(2).dependencies end end describe "#number_with_delimiter(number, delimiter = ',', separator = '.')" do let(:command) { Gem::Commands::AppraiserCommand.new } context "number is 0" do let(:number) { 0 } subject { command.send(:number_with_delimiter, number) } it { should eq('0') } end context "number is 100" do let(:number) { 100 } subject { command.send(:number_with_delimiter, number) } it { should eq('100') } end context "number is 1000" do let(:number) { 1000 } subject { command.send(:number_with_delimiter, number) } it { should eq('1,000') } end context "number is 10000.99" do let(:number) { 10000.99 } subject { command.send(:number_with_delimiter, number) } it { should eq('10,000.99') } end context "number is 1000000" do let(:number) { 1000000 } subject { command.send(:number_with_delimiter, number) } it { should eq('1,000,000') } end context "number is 1000000, delimiter is '_'" do let(:number) { 1000000 } let(:delimiter) { '_' } subject { command.send(:number_with_delimiter, number, delimiter) } it { should eq('1_000_000') } end context "number is '1000000 00', delimiter is '_', separator is ' '" do let(:number) { 1000000 } let(:delimiter) { '_' } let(:separator) { ' ' } subject { command.send(:number_with_delimiter, number, delimiter, separator) } it { should eq('1_000_000') } end end end appraiser-0.2.0/CHANGELOG0000644000175000017500000000060712646023310013307 0ustar aleealee== 0.2.0 * update for Bundler 1.3 == 0.1.7 * fix .travis.yml placement == 0.1.6 * add specs for Gem::Commands::AppraiserCommand * testing on travis-ci.org == 0.1.5 * gem commandify [amatsuda] The CLI command moved to a Rubygems' subcommand. example: (basic) $ gem appraiser (shorthand) $ gem a ("group" option) $ gem a -g test == 0.1.4 * First release appraiser-0.2.0/lib/0000755000175000017500000000000012646023310012640 5ustar aleealeeappraiser-0.2.0/lib/appraiser/0000755000175000017500000000000012646023310014626 5ustar aleealeeappraiser-0.2.0/lib/appraiser/version.rb0000644000175000017500000000011312646023310016633 0ustar aleealee# -*- coding: utf-8 -*- module Appraiser VERSION = "0.2.0" end appraiser-0.2.0/lib/rubygems_plugin.rb0000644000175000017500000000016512646023310016402 0ustar aleealee# -*- coding: utf-8 -*- require 'rubygems/command_manager' Gem::CommandManager.instance.register_command :appraiser appraiser-0.2.0/lib/rubygems/0000755000175000017500000000000012646023310014475 5ustar aleealeeappraiser-0.2.0/lib/rubygems/commands/0000755000175000017500000000000012646023310016276 5ustar aleealeeappraiser-0.2.0/lib/rubygems/commands/appraiser_command.rb0000644000175000017500000000450012646023310022306 0ustar aleealee# -*- coding: utf-8 -*- require 'rubygems/command' require 'rubygems/dependency' require 'bundler' require 'colored' require 'json' require 'open-uri' require 'stringio' require 'appraiser/version' class Gem::Commands::AppraiserCommand < Gem::Command RUBY_GEMS_URL = 'http://rubygems.org/api/v1/gems/%s.json' LINE = '-' * 60 def initialize super 'appraiser', 'Display gem information in ./Gemfile' add_option('-g', '--group=GROUP', 'Group') do |group, options| options[:group] = group end end def usage # :nodoc: "#{program_name} [-g group]" end def execute process($stdout) end private # @param [IO] output def process(output) group = (options[:group] || :default).to_sym dependencies_for(group).each do |dependency| json = load_json(dependency.name) if json.empty? output.puts dependency.name.green output.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 output.puts "#{name.green} (by #{authors})" output.puts "Downloads: #{downloads.blue}" output.puts "Project : #{project_uri.cyan.underline}" if project_uri output.puts "Document : #{doc_uri.cyan.underline}" if doc_uri output.puts "Source : #{src_uri.cyan.underline}" if src_uri output.puts info end output.puts LINE end end # @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] 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 appraiser-0.2.0/.gitignore0000644000175000017500000000006612646023310014064 0ustar aleealee*.gem .bundle .rvmrc .ruby-version Gemfile.lock pkg/* appraiser-0.2.0/LICENSE.txt0000644000175000017500000000203712646023310013717 0ustar aleealeeCopyright (c) 2013 Junya Ogura Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. appraiser-0.2.0/.travis.yml0000644000175000017500000000011012646023310014173 0ustar aleealeelanguage: ruby rvm: - 1.9.3 - 2.0.0 - jruby-19mode - rbx-19mode appraiser-0.2.0/README.md0000644000175000017500000000157512646023310013361 0ustar aleealee# Appraiser = a simple rubygems subcommand for Gemfile [![Build Status](https://travis-ci.org/juno/appraiser.png?branch=master)](https://travis-ci.org/juno/appraiser) `appraiser` displays gem information from `./Gemfile`. Like this: ![Screenshot](http://farm6.staticflickr.com/5263/5650073256_6ed10dc831_o.png) ## Install appraiser installed as a rubygems subcommand. $ gem install appraiser $ gem help commands | grep appraiser appraiser Display gem information in ./Gemfile ## Usage Normally displays runtime dependencies. $ cd /path/to/project_with_Gemfile/ $ gem appraiser or, displays other dependencies with `-g GROUP`. $ gem appraiser -g development ## Contributing Once you've made your great commits: Fork, fix, then send me a pull request. ## Copyright Copyright (c) 2011-2013 Junya Ogura. See LICENSE.txt for further details. appraiser-0.2.0/Gemfile0000644000175000017500000000004712646023310013366 0ustar aleealeesource "https://rubygems.org" gemspec appraiser-0.2.0/metadata.yml0000644000175000017500000000703012646023310014375 0ustar aleealee--- !ruby/object:Gem::Specification name: appraiser version: !ruby/object:Gem::Version version: 0.2.0 platform: ruby authors: - Junya Ogura autorequire: bindir: bin cert_chain: [] date: 2013-04-04 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: bundler requirement: !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version version: '1.3' type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version version: '1.3' - !ruby/object:Gem::Dependency name: colored requirement: !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version version: '1.2' type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version version: '1.2' - !ruby/object:Gem::Dependency name: json requirement: !ruby/object:Gem::Requirement requirements: - - '>=' - !ruby/object:Gem::Version version: '0' type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - '>=' - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: rake requirement: !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version version: '10.0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version version: '10.0' - !ruby/object:Gem::Dependency name: rspec requirement: !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version version: '2.13' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version version: '2.13' - !ruby/object:Gem::Dependency name: webmock requirement: !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version version: '1.11' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version version: '1.11' description: '`appraiser` is a rubygems subcommand which displays gem information in `./Gemfile`.' email: - junyaogura@gmail.com executables: [] extensions: [] extra_rdoc_files: [] files: - .gitignore - .rspec - .travis.yml - CHANGELOG - Gemfile - LICENSE.txt - README.md - Rakefile - appraiser.gemspec - lib/appraiser/version.rb - lib/rubygems/commands/appraiser_command.rb - lib/rubygems_plugin.rb - spec/appraiser_spec.rb - spec/spec_helper.rb homepage: https://github.com/juno/appraiser licenses: - MIT metadata: {} post_install_message: |2+ appraiser installed as a rubygems subcommand. (basic) $ gem appraiser (shorthand) $ gem a ("group" option) $ gem a -g test rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement requirements: - - '>=' - !ruby/object:Gem::Version version: '0' required_rubygems_version: !ruby/object:Gem::Requirement requirements: - - '>=' - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: rubygems_version: 2.0.0 signing_key: specification_version: 4 summary: '`appraiser` is a simple rubygems subcommand for Gemfile.' test_files: - spec/appraiser_spec.rb - spec/spec_helper.rb appraiser-0.2.0/.rspec0000644000175000017500000000001012646023310013176 0ustar aleealee--color