gemline 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - rbx-2.0
6
+ - jruby
data/README.rdoc CHANGED
@@ -17,3 +17,10 @@ If possible, we'll also copy that Gemfile line into the clipboard using pbcopy.
17
17
  == Usage
18
18
 
19
19
  # gemline [GEM NAME]
20
+
21
+ == Upcoming features
22
+
23
+ * A --pre option to grab the latest prerelease version
24
+ * An --open option to open the gem's rubygems.org page in the default browser
25
+ * Switching to a real command line parser instead of the lazy code in place now to allow the addition of the above options
26
+
data/Rakefile CHANGED
@@ -1,2 +1,15 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
+ require 'rspec'
4
+ require 'rspec/core/rake_task'
5
+
6
+ Bundler::GemHelper.install_tasks
7
+
8
+ desc 'Default: Run specs'
9
+ task :default => :spec
10
+
11
+ desc 'Run specs'
12
+ RSpec::Core::RakeTask.new(:spec)
13
+
14
+ desc 'Run specs (alias for Gem Testers)'
15
+ task :test => :spec
data/gemline.gemspec CHANGED
@@ -13,8 +13,9 @@ Gem::Specification.new do |gem|
13
13
  gem.name = "gemline"
14
14
  gem.require_paths = ["lib"]
15
15
 
16
- gem.version = '0.0.4'
16
+ gem.version = '0.1.0'
17
17
 
18
18
  gem.add_dependency('crack')
19
+ gem.add_development_dependency('rake') # For Travis CI
19
20
  gem.add_development_dependency(%q<rspec>, [">= 2.7.0"])
20
21
  end
data/lib/gemline.rb CHANGED
@@ -1,18 +1,23 @@
1
+ Encoding.default_external = Encoding::UTF_8
2
+
1
3
  require 'crack/json'
2
4
  require 'net/http'
3
5
 
6
+ require 'yaml'
7
+ YAML::ENGINE.yamler = 'syck'
8
+
4
9
 
5
10
  class Gemline
6
11
  attr_accessor :gem, :gemline, :json, :response
7
12
 
8
- def self.query(gem)
9
- gem = gem.to_s.gsub(/[^\w\-]+/,'')
10
- check_input(gem)
13
+ def self.query(gem_name)
14
+ gem_name = gem_name.to_s.gsub(/[^\w\-]+/,'')
15
+ check_input(gem_name)
11
16
 
12
- g = Gemline.new(gem)
13
-
17
+ g = Gemline.new(gem_name)
18
+
14
19
  if g.gem_not_found?
15
- puts "Rubygem #{gem} was not found on rubygems.org"
20
+ puts "Ruby gem #{gem_name} was not found on rubygems.org"
16
21
  exit
17
22
  else
18
23
  puts g.gemline
@@ -21,8 +26,8 @@ class Gemline
21
26
  end
22
27
 
23
28
 
24
- def initialize(gem)
25
- @gem = gem.to_s.gsub(/[^\w\-]+/,'') # Yeah, a little over-defensive.
29
+ def initialize(gem_name)
30
+ @gem = gem_name.to_s.gsub(/[^\w\-]+/,'') # Yeah, a little over-defensive.
26
31
  @json = Gemline.get_rubygem_json(@gem)
27
32
  unless gem_not_found?
28
33
  @response = Crack::JSON.parse(@json)
@@ -31,28 +36,28 @@ class Gemline
31
36
  end
32
37
 
33
38
  def gem_not_found?
34
- @json.match(/could not be found/)
39
+ @json.match(/(could not be found|does not exist)/)
35
40
  end
36
41
 
37
42
 
38
43
  private
39
44
 
40
- def self.get_rubygem_json(gem)
41
- Net::HTTP.get(URI.parse("http://rubygems.org/api/v1/gems/#{gem}.json"))
45
+ def self.get_rubygem_json(gem_name)
46
+ Net::HTTP.get(URI.parse("http://rubygems.org/api/v1/gems/#{gem_name}.json"))
42
47
  end
43
48
 
44
- def self.create_gemline(gem, version)
45
- %Q{gem "#{gem}", "~> #{version}"}
49
+ def self.create_gemline(gem_name, version)
50
+ %Q{gem "#{gem_name}", "~> #{version}"}
46
51
  end
47
52
 
48
- def self.check_input(gem)
49
- if (gem.empty? || ['-h','--help','help'].include?(gem))
53
+ def self.check_input(gem_name)
54
+ if (gem_name.empty? || ['-h','--help','help'].include?(gem_name))
50
55
  puts "Usage: gemline [GEM NAME]"
51
56
  puts " Prints a Gemfile require line for a Ruby gem on Rubygems.org"
52
57
  exit
53
58
  end
54
59
 
55
- # if (['-v','--version'].include?(gem))
60
+ # if (['-v','--version'].include?(gem_name))
56
61
  # puts "gemline #{Gemline::VERSION}"
57
62
  # exit
58
63
  # end
@@ -65,6 +70,8 @@ class Gemline
65
70
  puts " Gem line copied to your clipboard. Ready to paste into your Gemfile"
66
71
  end
67
72
  rescue
73
+ ## Yeah, I hate this too. But it does what I want -- silently fail if pbcopy isn't available.
74
+ ## TODO: Use something more reliable and cross-platform.
68
75
  end
69
76
  end
70
77
 
data/spec/gemline_spec.rb CHANGED
@@ -4,9 +4,10 @@ describe Gemline do
4
4
 
5
5
  describe "querying rubygems" do
6
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")))
7
+ before do
8
+ Dir.glob(File.join(File.dirname(__FILE__),'samples', '*.json')).each do |f|
9
+ gem_name = $1 if f =~ /\/([\w\-]+).json$/
10
+ Gemline.stub!(:get_rubygem_json).with(gem_name).and_return(IO.read(f))
10
11
  end
11
12
  end
12
13
 
@@ -20,6 +21,17 @@ describe Gemline do
20
21
  g.gem_not_found?.should be_true
21
22
  g.gemline.should be_nil
22
23
  end
24
+
25
+ it "should properly detect a blocked gem name" do
26
+ g = Gemline.new('yaml')
27
+ g.gem_not_found?.should be_true
28
+ g.gemline.should be_nil
29
+ end
30
+
31
+ it "should properly handle funny characters in the returned JSON" do
32
+ g = Gemline.new('nokogiri')
33
+ g.gemline.should == %Q{gem "nokogiri", "~> 1.5.5"}
34
+ end
23
35
  end
24
36
 
25
37
  end
@@ -1,2 +1 @@
1
-
2
1
  This rubygem could not be found.
@@ -0,0 +1 @@
1
+ {"name":"nokogiri","downloads":5007271,"version":"1.5.5","version_downloads":350,"authors":"Aaron Patterson, Mike Dalessio, Yoko Harada, Tim Elliott","info":"Nokogiri (\u00e9\u008b\u00b8) is an HTML, XML, SAX, and Reader parser. Among Nokogiri's\nmany features is the ability to search documents via XPath or CSS3 selectors.\n\nXML is like violence - if it doesn\u00e2\u0080\u0099t solve your problems, you are not using\nenough of it.","project_uri":"http://rubygems.org/gems/nokogiri","gem_uri":"http://rubygems.org/gems/nokogiri-1.5.5.gem","homepage_uri":"http://nokogiri.org","wiki_uri":"","documentation_uri":"http://nokogiri.org","mailing_list_uri":"http://groups.google.com/group/nokogiri-talk","source_code_uri":"https://github.com/sparklemotion/nokogiri","bug_tracker_uri":"https://github.com/sparklemotion/nokogiri/issues","dependencies":{"development":[{"name":"hoe","requirements":"~> 2.16"},{"name":"hoe-bundler","requirements":">= 1.1"},{"name":"hoe-debugging","requirements":">= 1.0.3"},{"name":"hoe-gemspec","requirements":">= 1.0"},{"name":"hoe-git","requirements":">= 1.4"},{"name":"mini_portile","requirements":">= 0.2.2"},{"name":"minitest","requirements":"~> 2.2.2"},{"name":"racc","requirements":">= 1.4.6"},{"name":"rake","requirements":">= 0.9"},{"name":"rake-compiler","requirements":"= 0.8.0"},{"name":"rdoc","requirements":"~> 3.10"},{"name":"rexical","requirements":">= 1.0.5"}],"runtime":[]}}
@@ -0,0 +1 @@
1
+ This gem does not exist.
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.4
4
+ version: 0.1.0
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-11-07 00:00:00.000000000 Z
12
+ date: 2012-06-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: crack
16
- requirement: &70298176333640 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,31 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70298176333640
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
25
46
  - !ruby/object:Gem::Dependency
26
47
  name: rspec
27
- requirement: &70298176333100 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
28
49
  none: false
29
50
  requirements:
30
51
  - - ! '>='
@@ -32,7 +53,12 @@ dependencies:
32
53
  version: 2.7.0
33
54
  type: :development
34
55
  prerelease: false
35
- version_requirements: *70298176333100
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 2.7.0
36
62
  description: Grab the latest Gemfile 'gem' line for a specific Ruby gem
37
63
  email:
38
64
  - joe@joealba.com
@@ -42,6 +68,7 @@ extensions: []
42
68
  extra_rdoc_files: []
43
69
  files:
44
70
  - .gitignore
71
+ - .travis.yml
45
72
  - Gemfile
46
73
  - README.rdoc
47
74
  - Rakefile
@@ -50,7 +77,9 @@ files:
50
77
  - lib/gemline.rb
51
78
  - spec/gemline_spec.rb
52
79
  - spec/samples/doesnotexist.json
80
+ - spec/samples/nokogiri.json
53
81
  - spec/samples/rails.json
82
+ - spec/samples/yaml.json
54
83
  - spec/spec_helper.rb
55
84
  homepage: http://github.com/joealba/gemline
56
85
  licenses: []
@@ -64,20 +93,28 @@ required_ruby_version: !ruby/object:Gem::Requirement
64
93
  - - ! '>='
65
94
  - !ruby/object:Gem::Version
66
95
  version: '0'
96
+ segments:
97
+ - 0
98
+ hash: -2384583455144954714
67
99
  required_rubygems_version: !ruby/object:Gem::Requirement
68
100
  none: false
69
101
  requirements:
70
102
  - - ! '>='
71
103
  - !ruby/object:Gem::Version
72
104
  version: '0'
105
+ segments:
106
+ - 0
107
+ hash: -2384583455144954714
73
108
  requirements: []
74
109
  rubyforge_project:
75
- rubygems_version: 1.8.10
110
+ rubygems_version: 1.8.24
76
111
  signing_key:
77
112
  specification_version: 3
78
113
  summary: ''
79
114
  test_files:
80
115
  - spec/gemline_spec.rb
81
116
  - spec/samples/doesnotexist.json
117
+ - spec/samples/nokogiri.json
82
118
  - spec/samples/rails.json
119
+ - spec/samples/yaml.json
83
120
  - spec/spec_helper.rb