gemline 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,13 +7,14 @@ Gem::Specification.new do |gem|
7
7
  gem.summary = %q{}
8
8
  gem.homepage = "http://github.com/joealba/gemline"
9
9
 
10
- gem.executables << 'gemline'
10
+ gem.executables = ['gemline']
11
11
  gem.files = `git ls-files`.split("\n")
12
12
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
13
13
  gem.name = "gemline"
14
14
  gem.require_paths = ["lib"]
15
- gem.version = '0.0.3'
15
+
16
+ gem.version = '0.0.4'
16
17
 
17
18
  gem.add_dependency('crack')
18
- # gem.add_development_dependency(%q<rspec>, [">= 2.7.0"])
19
+ gem.add_development_dependency(%q<rspec>, [">= 2.7.0"])
19
20
  end
@@ -1,34 +1,70 @@
1
1
  require 'crack/json'
2
2
  require 'net/http'
3
3
 
4
+
4
5
  class Gemline
6
+ attr_accessor :gem, :gemline, :json, :response
5
7
 
6
8
  def self.query(gem)
7
9
  gem = gem.to_s.gsub(/[^\w\-]+/,'')
8
- if (gem.empty? || ['-h','--help','help'].include?(gem))
9
- puts "Usage: gemline [GEM NAME]"
10
- puts " Prints a Gemfile require line for a Ruby gem on Rubygems.org"
11
- exit
12
- end
13
-
14
- doc = Net::HTTP.get(URI.parse("http://rubygems.org/api/v1/gems/#{gem}.json"))
10
+ check_input(gem)
15
11
 
16
- if doc.match(/could not be found/)
12
+ g = Gemline.new(gem)
13
+
14
+ if g.gem_not_found?
17
15
  puts "Rubygem #{gem} was not found on rubygems.org"
18
16
  exit
19
17
  else
20
- response = Crack::JSON.parse(doc)
21
- gemline = %Q{gem "#{gem}", "~> #{response['version']}"}
18
+ puts g.gemline
19
+ copy_to_clipboard(g.gemline)
20
+ end
21
+ end
22
+
23
+
24
+ def initialize(gem)
25
+ @gem = gem.to_s.gsub(/[^\w\-]+/,'') # Yeah, a little over-defensive.
26
+ @json = Gemline.get_rubygem_json(@gem)
27
+ unless gem_not_found?
28
+ @response = Crack::JSON.parse(@json)
29
+ @gemline = Gemline.create_gemline(@gem, response['version'])
30
+ end
31
+ end
22
32
 
23
- puts gemline
33
+ def gem_not_found?
34
+ @json.match(/could not be found/)
35
+ end
36
+
37
+
38
+ private
39
+
40
+ def self.get_rubygem_json(gem)
41
+ Net::HTTP.get(URI.parse("http://rubygems.org/api/v1/gems/#{gem}.json"))
42
+ end
43
+
44
+ def self.create_gemline(gem, version)
45
+ %Q{gem "#{gem}", "~> #{version}"}
46
+ end
47
+
48
+ def self.check_input(gem)
49
+ if (gem.empty? || ['-h','--help','help'].include?(gem))
50
+ puts "Usage: gemline [GEM NAME]"
51
+ puts " Prints a Gemfile require line for a Ruby gem on Rubygems.org"
52
+ exit
53
+ end
54
+
55
+ # if (['-v','--version'].include?(gem))
56
+ # puts "gemline #{Gemline::VERSION}"
57
+ # exit
58
+ # end
59
+ end
24
60
 
25
- begin
26
- if clipboard = IO.popen('pbcopy', 'r+')
27
- clipboard.puts gemline
28
- puts " Gem line copied to your clipboard. Ready to paste into your Gemfile"
29
- end
30
- rescue
61
+ def self.copy_to_clipboard(gemline)
62
+ begin
63
+ if clipboard = IO.popen('pbcopy', 'r+')
64
+ clipboard.puts gemline
65
+ puts " Gem line copied to your clipboard. Ready to paste into your Gemfile"
31
66
  end
67
+ rescue
32
68
  end
33
69
  end
34
70
 
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gemline do
4
+
5
+ describe "querying rubygems" do
6
+
7
+ before do
8
+ ['rails','doesnotexist'].each do |arg|
9
+ Gemline.stub!(:get_rubygem_json).with(arg).and_return(IO.read(File.join(File.dirname(__FILE__),'samples',"#{arg}.json")))
10
+ end
11
+ end
12
+
13
+ it "should be able to parse the version out of a good json string" do
14
+ g = Gemline.new('rails')
15
+ g.gemline.should == %Q{gem "rails", "~> 3.1.1"}
16
+ end
17
+
18
+ it "should whine when the gem you are querying does not exist" do
19
+ g = Gemline.new('doesnotexist')
20
+ g.gem_not_found?.should be_true
21
+ g.gemline.should be_nil
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1,2 @@
1
+
2
+ This rubygem could not be found.
@@ -0,0 +1 @@
1
+ {"dependencies":{"runtime":[{"name":"actionmailer","requirements":"= 3.1.1"},{"name":"actionpack","requirements":"= 3.1.1"},{"name":"activerecord","requirements":"= 3.1.1"},{"name":"activeresource","requirements":"= 3.1.1"},{"name":"activesupport","requirements":"= 3.1.1"},{"name":"bundler","requirements":"~> 1.0"},{"name":"railties","requirements":"= 3.1.1"}],"development":[]},"name":"rails","downloads":6177950,"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":176339,"version":"3.1.1","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.1.1.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"}
@@ -0,0 +1,13 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require 'rubygems'
5
+ require 'gemline'
6
+
7
+ require 'bundler'
8
+ Bundler.setup
9
+
10
+
11
+ RSpec.configure do |c|
12
+
13
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gemline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-28 00:00:00.000000000Z
12
+ date: 2011-11-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: crack
16
- requirement: &70095766739220 !ruby/object:Gem::Requirement
16
+ requirement: &70298176333640 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,18 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70095766739220
24
+ version_requirements: *70298176333640
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70298176333100 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 2.7.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70298176333100
25
36
  description: Grab the latest Gemfile 'gem' line for a specific Ruby gem
26
37
  email:
27
38
  - joe@joealba.com
@@ -37,6 +48,10 @@ files:
37
48
  - bin/gemline
38
49
  - gemline.gemspec
39
50
  - lib/gemline.rb
51
+ - spec/gemline_spec.rb
52
+ - spec/samples/doesnotexist.json
53
+ - spec/samples/rails.json
54
+ - spec/spec_helper.rb
40
55
  homepage: http://github.com/joealba/gemline
41
56
  licenses: []
42
57
  post_install_message:
@@ -57,8 +72,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
57
72
  version: '0'
58
73
  requirements: []
59
74
  rubyforge_project:
60
- rubygems_version: 1.8.11
75
+ rubygems_version: 1.8.10
61
76
  signing_key:
62
77
  specification_version: 3
63
78
  summary: ''
64
- test_files: []
79
+ test_files:
80
+ - spec/gemline_spec.rb
81
+ - spec/samples/doesnotexist.json
82
+ - spec/samples/rails.json
83
+ - spec/spec_helper.rb