gemline 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/gemline.gemspec +1 -1
- data/lib/gemline.rb +22 -9
- data/spec/acceptance_spec.rb +21 -0
- data/spec/gemline_spec.rb +7 -4
- data/spec/spec_helper.rb +20 -0
- metadata +4 -8
data/gemline.gemspec
CHANGED
data/lib/gemline.rb
CHANGED
@@ -15,8 +15,8 @@ class Gemline
|
|
15
15
|
g = Gemline.new(gem_name)
|
16
16
|
|
17
17
|
if g.gem_not_found?
|
18
|
-
puts "Ruby gem #{gem_name} was not found on rubygems.org"
|
19
|
-
exit
|
18
|
+
$stderr.puts "Ruby gem #{gem_name} was not found on rubygems.org"
|
19
|
+
Kernel.exit 1
|
20
20
|
else
|
21
21
|
puts g.gemline
|
22
22
|
copy_to_clipboard(g.gemline)
|
@@ -24,12 +24,12 @@ class Gemline
|
|
24
24
|
end
|
25
25
|
|
26
26
|
|
27
|
-
def initialize(gem_name)
|
27
|
+
def initialize(gem_name, options = {})
|
28
28
|
@gem = gem_name.to_s.gsub(/[^\w\-]+/,'') # Yeah, a little over-defensive.
|
29
29
|
@json = Gemline.get_rubygem_json(@gem)
|
30
30
|
unless gem_not_found?
|
31
31
|
@response = Crack::JSON.parse(@json)
|
32
|
-
@gemline = Gemline.create_gemline(@gem, response['version'])
|
32
|
+
@gemline = Gemline.create_gemline(@gem, response['version'], options)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -44,15 +44,28 @@ class Gemline
|
|
44
44
|
Net::HTTP.get(URI.parse("http://rubygems.org/api/v1/gems/#{gem_name}.json"))
|
45
45
|
end
|
46
46
|
|
47
|
-
def self.create_gemline(gem_name, version)
|
47
|
+
def self.create_gemline(gem_name, version, options = {})
|
48
|
+
if options[:gemspec]
|
49
|
+
return gemspec_gemline(gem_name, version)
|
50
|
+
else
|
51
|
+
return gemfile_gemline(gem_name, version)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.gemfile_gemline(gem_name, version)
|
48
56
|
%Q{gem "#{gem_name}", "~> #{version}"}
|
49
57
|
end
|
50
58
|
|
59
|
+
def self.gemspec_gemline(gem_name, version)
|
60
|
+
%Q{gem.add_dependency(%q<#{gem_name}>, ["~> #{version}"])}
|
61
|
+
end
|
62
|
+
|
63
|
+
|
51
64
|
def self.check_input(gem_name)
|
52
65
|
if (gem_name.empty? || ['-h','--help','help'].include?(gem_name))
|
53
|
-
puts "Usage: gemline [GEM NAME]"
|
54
|
-
puts " Prints a Gemfile require line for a Ruby gem on Rubygems.org"
|
55
|
-
exit
|
66
|
+
$stderr.puts "Usage: gemline [GEM NAME]"
|
67
|
+
$stderr.puts " Prints a Gemfile require line for a Ruby gem on Rubygems.org"
|
68
|
+
Kernel.exit 1
|
56
69
|
end
|
57
70
|
|
58
71
|
# if (['-v','--version'].include?(gem_name))
|
@@ -65,7 +78,7 @@ class Gemline
|
|
65
78
|
begin
|
66
79
|
if clipboard = IO.popen('pbcopy', 'r+')
|
67
80
|
clipboard.puts gemline
|
68
|
-
puts " Gem line copied to your clipboard. Ready to paste into your Gemfile"
|
81
|
+
$stderr.puts " Gem line copied to your clipboard. Ready to paste into your Gemfile"
|
69
82
|
end
|
70
83
|
rescue
|
71
84
|
## Yeah, I hate this too. But it does what I want -- silently fail if pbcopy isn't available.
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'stringio'
|
3
|
+
|
4
|
+
describe "gemline output" do
|
5
|
+
|
6
|
+
before do
|
7
|
+
stub_rubygems_json_output
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should output one line to STDOUT so the output can be appended to a Gemfile" do
|
11
|
+
grab_io { Gemline.query('rails') }
|
12
|
+
@stdout.readlines.count.should eq(1)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should output nothing to STDOUT on error" do
|
16
|
+
Kernel.stub(:exit)
|
17
|
+
grab_io { Gemline.query('doesnotexist') }
|
18
|
+
@stdout.readlines.count.should eq(0)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
data/spec/gemline_spec.rb
CHANGED
@@ -5,10 +5,7 @@ describe Gemline do
|
|
5
5
|
describe "querying rubygems" do
|
6
6
|
|
7
7
|
before do
|
8
|
-
|
9
|
-
gem_name = $1 if f =~ /\/([\w\-]+).json$/
|
10
|
-
Gemline.stub!(:get_rubygem_json).with(gem_name).and_return(IO.read(f))
|
11
|
-
end
|
8
|
+
stub_rubygems_json_output
|
12
9
|
end
|
13
10
|
|
14
11
|
it "should be able to parse the version out of a good json string" do
|
@@ -32,6 +29,12 @@ describe Gemline do
|
|
32
29
|
g = Gemline.new('nokogiri')
|
33
30
|
g.gemline.should == %Q{gem "nokogiri", "~> 1.5.5"}
|
34
31
|
end
|
32
|
+
|
33
|
+
it "should be able to generate a gemspec-style gemline" do
|
34
|
+
g = Gemline.new('rails', :gemspec => true)
|
35
|
+
g.gemline.should == %Q!gem.add_dependency(%q<rails>, ["~> 3.1.1"])!
|
36
|
+
end
|
37
|
+
|
35
38
|
end
|
36
39
|
|
37
40
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -11,3 +11,23 @@ Bundler.setup
|
|
11
11
|
RSpec.configure do |c|
|
12
12
|
|
13
13
|
end
|
14
|
+
|
15
|
+
|
16
|
+
def stub_rubygems_json_output
|
17
|
+
Dir.glob(File.join(File.dirname(__FILE__),'samples', '*.json')).each do |f|
|
18
|
+
gem_name = $1 if f =~ /\/([\w\-]+).json$/
|
19
|
+
Gemline.stub!(:get_rubygem_json).with(gem_name).and_return(IO.read(f))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def grab_io
|
24
|
+
@stdout = StringIO.new; $stdout = @stdout;
|
25
|
+
@stderr = StringIO.new; $stderr = @stderr;
|
26
|
+
|
27
|
+
yield
|
28
|
+
|
29
|
+
@stdout.rewind; @stderr.rewind;
|
30
|
+
|
31
|
+
$stdout = STDOUT
|
32
|
+
$stderr = STDERR
|
33
|
+
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.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-07-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: crack
|
@@ -75,6 +75,7 @@ files:
|
|
75
75
|
- bin/gemline
|
76
76
|
- gemline.gemspec
|
77
77
|
- lib/gemline.rb
|
78
|
+
- spec/acceptance_spec.rb
|
78
79
|
- spec/gemline_spec.rb
|
79
80
|
- spec/samples/doesnotexist.json
|
80
81
|
- spec/samples/nokogiri.json
|
@@ -93,18 +94,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
93
94
|
- - ! '>='
|
94
95
|
- !ruby/object:Gem::Version
|
95
96
|
version: '0'
|
96
|
-
segments:
|
97
|
-
- 0
|
98
|
-
hash: 1346520356031458065
|
99
97
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
98
|
none: false
|
101
99
|
requirements:
|
102
100
|
- - ! '>='
|
103
101
|
- !ruby/object:Gem::Version
|
104
102
|
version: '0'
|
105
|
-
segments:
|
106
|
-
- 0
|
107
|
-
hash: 1346520356031458065
|
108
103
|
requirements: []
|
109
104
|
rubyforge_project:
|
110
105
|
rubygems_version: 1.8.24
|
@@ -112,6 +107,7 @@ signing_key:
|
|
112
107
|
specification_version: 3
|
113
108
|
summary: ''
|
114
109
|
test_files:
|
110
|
+
- spec/acceptance_spec.rb
|
115
111
|
- spec/gemline_spec.rb
|
116
112
|
- spec/samples/doesnotexist.json
|
117
113
|
- spec/samples/nokogiri.json
|