gemline 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +1 -0
- data/README.rdoc +30 -3
- data/bin/gemline +38 -2
- data/gemline.gemspec +3 -2
- data/lib/gemline.rb +28 -32
- data/spec/gemline_spec.rb +48 -3
- data/spec/spec_helper.rb +8 -1
- metadata +34 -37
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 40c67d8b6da4db9e5c1e72ec503472e777ffb236
|
4
|
+
data.tar.gz: bfed976a867e9dbaa5ebf34ef6bb3adf8d594ecc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 81b9ece9c9252124be218de2b1fab46f584f3925bd3b044ca495c8a49f805825d0c94bd91a171a55a6f16dc37dba50f09421a1288fd58eb4b7e2804fe700f370
|
7
|
+
data.tar.gz: 05714764adb0dd2e420989e23e5a60afdf2b4f52a91b6b13b9db29b13b3dfbbed126f74666117d0f50e0f599726dbfac6bb4c33cf7df3e6a2a098dea3083622c
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/README.rdoc
CHANGED
@@ -4,12 +4,40 @@ Create a tilde-arrow Gemfile line for a gem on rubygems.org using the latest ver
|
|
4
4
|
|
5
5
|
If possible, we'll also copy that Gemfile line into the clipboard using pbcopy.
|
6
6
|
|
7
|
-
==
|
7
|
+
== Examples
|
8
|
+
|
9
|
+
=== Normal Gemfile usage
|
8
10
|
|
9
11
|
# gemline rails
|
10
|
-
gem "rails", "~>
|
12
|
+
gem "rails", "~> 4.0.1"
|
13
|
+
Gem line copied to your clipboard. Ready to paste into your Gemfile
|
14
|
+
|
15
|
+
=== Including group designation
|
16
|
+
|
17
|
+
# gemline rails --group development,test
|
18
|
+
gem "rails", "~> 4.0.1", :group => [:development, :test]
|
11
19
|
Gem line copied to your clipboard. Ready to paste into your Gemfile
|
12
20
|
|
21
|
+
=== Append your Gemfile
|
22
|
+
|
23
|
+
# gemline rails >> Gemfile
|
24
|
+
|
25
|
+
=== Gemspec style
|
26
|
+
|
27
|
+
# gemline rails -g
|
28
|
+
gem.add_dependency "rails", "~> 4.0.1"
|
29
|
+
Gem line copied to your clipboard. Ready to paste into your Gemfile
|
30
|
+
|
31
|
+
# gemline rails -g --group development
|
32
|
+
gem.add_development_dependency "rails", "~> 4.0.1"
|
33
|
+
Gem line copied to your clipboard. Ready to paste into your Gemfile
|
34
|
+
|
35
|
+
=== Gemline -- It's not just for the command line anymore. You can use it in your bootstrapping code too.
|
36
|
+
|
37
|
+
require 'gemline'
|
38
|
+
puts Gemline.new('rails').gemline
|
39
|
+
puts Gemline.new('rails', :group => :development).gemline
|
40
|
+
|
13
41
|
== Install
|
14
42
|
|
15
43
|
# gem install gemline
|
@@ -22,5 +50,4 @@ If possible, we'll also copy that Gemfile line into the clipboard using pbcopy.
|
|
22
50
|
|
23
51
|
* A --pre option to grab the latest prerelease version
|
24
52
|
* 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
53
|
|
data/bin/gemline
CHANGED
@@ -1,13 +1,49 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require "gemline"
|
4
|
+
require 'optparse'
|
4
5
|
|
5
6
|
## TODO: Real command line parsing to support some switches
|
6
7
|
## for things like:
|
7
8
|
## --pre : Get latest pre-release version
|
8
|
-
## --gemspec or -g : Get the gemspec version of the gemline
|
9
9
|
## --major N : Get latest version of gem within the given major release number
|
10
10
|
## --web or -w : Get rubygems.org link
|
11
|
+
|
12
|
+
def self.help_message
|
13
|
+
puts "Usage: gemline [GEM NAME]"
|
14
|
+
puts " Prints a Gemfile require line for a Ruby gem on Rubygems.org"
|
15
|
+
exit
|
16
|
+
end
|
17
|
+
|
18
|
+
options = {}
|
19
|
+
OptionParser.new do |opts|
|
20
|
+
opts.banner = "Usage: gemline gem_name [options]"
|
21
|
+
|
22
|
+
opts.on("--gemspec", "-g") do |g|
|
23
|
+
options[:gemspec] = g
|
24
|
+
end
|
25
|
+
|
26
|
+
opts.on("--group x,y,z", Array) do |group|
|
27
|
+
group = group[0] if group.size == 1
|
28
|
+
options[:group] = group
|
29
|
+
end
|
30
|
+
|
31
|
+
opts.on("--git x", String) do |git|
|
32
|
+
options[:git] = git
|
33
|
+
end
|
34
|
+
|
35
|
+
opts.on("-v", "--version") do
|
36
|
+
puts "gemline #{Gem::Specification::load("gemline.gemspec").version}"
|
37
|
+
exit
|
38
|
+
end
|
39
|
+
|
40
|
+
opts.on("-h", "--help", "help") do
|
41
|
+
help_message
|
42
|
+
end
|
43
|
+
end.parse!
|
44
|
+
|
11
45
|
gem = STDIN.tty? ? ARGV[0] : STDIN.read
|
12
46
|
|
13
|
-
|
47
|
+
help_message unless gem
|
48
|
+
|
49
|
+
Gemline.query(gem, options)
|
data/gemline.gemspec
CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |gem|
|
|
13
13
|
gem.name = "gemline"
|
14
14
|
gem.require_paths = ["lib"]
|
15
15
|
|
16
|
-
gem.version = '0.
|
16
|
+
gem.version = '0.4.0'
|
17
17
|
|
18
18
|
gem.add_dependency "json_pure", ">= 1.7.6"
|
19
19
|
gem.add_dependency "clipboard", ">= 1.0.1"
|
@@ -25,5 +25,6 @@ Gem::Specification.new do |gem|
|
|
25
25
|
# end
|
26
26
|
|
27
27
|
gem.add_development_dependency "rake" # For Travis CI
|
28
|
-
gem.add_development_dependency "rspec", ">= 2.
|
28
|
+
gem.add_development_dependency "rspec", ">= 2.14.0"
|
29
|
+
gem.add_development_dependency "simplecov", "~> 0.7.1"
|
29
30
|
end
|
data/lib/gemline.rb
CHANGED
@@ -5,11 +5,8 @@ require 'clipboard'
|
|
5
5
|
class Gemline
|
6
6
|
attr_accessor :gem, :gemline, :json, :response
|
7
7
|
|
8
|
-
def self.query(gem_name)
|
9
|
-
|
10
|
-
check_input(gem_name)
|
11
|
-
|
12
|
-
g = Gemline.new(gem_name)
|
8
|
+
def self.query(gem_name, options = {})
|
9
|
+
g = Gemline.new(gem_name, options)
|
13
10
|
|
14
11
|
if g.gem_not_found?
|
15
12
|
$stderr.puts "Ruby gem #{gem_name} was not found on rubygems.org"
|
@@ -20,13 +17,8 @@ class Gemline
|
|
20
17
|
end
|
21
18
|
end
|
22
19
|
|
23
|
-
def self.sanitize_gem_name(gem_name)
|
24
|
-
gem_name.to_s.gsub(/[^\w\-]+/,'')
|
25
|
-
end
|
26
|
-
|
27
|
-
|
28
20
|
def initialize(gem_name, options = {})
|
29
|
-
@gem = gem_name
|
21
|
+
@gem = sanitize_gem_name(gem_name)
|
30
22
|
@json = Gemline.get_rubygem_json(@gem)
|
31
23
|
unless gem_not_found?
|
32
24
|
@response = JSON.parse(@json)
|
@@ -34,13 +26,17 @@ class Gemline
|
|
34
26
|
end
|
35
27
|
end
|
36
28
|
|
29
|
+
def sanitize_gem_name(gem_name)
|
30
|
+
gem_name.to_s.gsub(/[^\w\-]+/,'') # Yeah, a little over-defensive.
|
31
|
+
end
|
32
|
+
|
37
33
|
def gem_not_found?
|
38
34
|
@json.match(/(could not be found|does not exist)/)
|
39
35
|
end
|
40
|
-
|
41
|
-
|
36
|
+
|
37
|
+
|
42
38
|
private
|
43
|
-
|
39
|
+
|
44
40
|
def self.get_rubygem_json(gem_name)
|
45
41
|
uri = URI.parse("https://rubygems.org/api/v1/gems/#{gem_name}.json")
|
46
42
|
http = Net::HTTP.new(uri.host, uri.port)
|
@@ -51,34 +47,34 @@ class Gemline
|
|
51
47
|
response.body
|
52
48
|
end
|
53
49
|
|
54
|
-
def self.create_gemline(gem_name, version, options
|
50
|
+
def self.create_gemline(gem_name, version, options)
|
55
51
|
if options[:gemspec]
|
56
|
-
return gemspec_gemline(gem_name, version)
|
52
|
+
return gemspec_gemline(gem_name, version, options)
|
57
53
|
else
|
58
|
-
return gemfile_gemline(gem_name, version)
|
54
|
+
return gemfile_gemline(gem_name, version, options.delete_if {|k,v| k == :gemspec})
|
59
55
|
end
|
60
56
|
end
|
61
57
|
|
62
|
-
def self.gemfile_gemline(gem_name, version)
|
63
|
-
%Q{gem "#{gem_name}", "~> #{version}"}
|
58
|
+
def self.gemfile_gemline(gem_name, version, options)
|
59
|
+
line = %Q{gem "#{gem_name}", "~> #{version}"}
|
60
|
+
line << ", " + options_to_string(options) if !options.empty?
|
61
|
+
line
|
64
62
|
end
|
65
63
|
|
66
|
-
def self.
|
67
|
-
|
64
|
+
def self.options_to_string(options = {})
|
65
|
+
if options[:group]
|
66
|
+
options[:group] = [options[:group]].flatten.map { |x| x.to_sym }
|
67
|
+
options[:group] = options[:group].first if options[:group].length == 1
|
68
|
+
end
|
69
|
+
options.inspect.delete('{}').gsub(/(?!\s)=>(?!\s)/, ' => ')
|
68
70
|
end
|
69
71
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
Kernel.exit 1
|
72
|
+
def self.gemspec_gemline(gem_name, version, options)
|
73
|
+
if options[:group] && options[:group].include?('development')
|
74
|
+
%Q{gem.add_development_dependency "#{gem_name}", "~> #{version}"}
|
75
|
+
else
|
76
|
+
%Q{gem.add_dependency "#{gem_name}", "~> #{version}"}
|
76
77
|
end
|
77
|
-
|
78
|
-
# if (['-v','--version'].include?(gem_name))
|
79
|
-
# puts "gemline #{Gemline::VERSION}"
|
80
|
-
# exit
|
81
|
-
# end
|
82
78
|
end
|
83
79
|
|
84
80
|
def self.copy_to_clipboard(gemline)
|
data/spec/gemline_spec.rb
CHANGED
@@ -4,7 +4,7 @@ describe Gemline do
|
|
4
4
|
|
5
5
|
describe "querying rubygems" do
|
6
6
|
|
7
|
-
before do
|
7
|
+
before do
|
8
8
|
stub_rubygems_json_output
|
9
9
|
end
|
10
10
|
|
@@ -12,7 +12,7 @@ describe Gemline do
|
|
12
12
|
g = Gemline.new('rails')
|
13
13
|
expect(g.gemline).to eq(%Q{gem "rails", "~> 3.1.1"})
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
it "should whine when the gem you are querying does not exist" do
|
17
17
|
g = Gemline.new('doesnotexist')
|
18
18
|
g.gem_not_found?.should be_true
|
@@ -32,9 +32,54 @@ describe Gemline do
|
|
32
32
|
|
33
33
|
it "should be able to generate a gemspec-style gemline" do
|
34
34
|
g = Gemline.new('rails', :gemspec => true)
|
35
|
-
expect(g.gemline).to eq(%Q!gem.add_dependency "rails", "
|
35
|
+
expect(g.gemline).to eq(%Q!gem.add_dependency "rails", "~> 3.1.1"!)
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "generates a development gemspec-style gemline" do
|
39
|
+
it "works when just passed the development group" do
|
40
|
+
g = Gemline.new('nokogiri', {:gemspec => true, :group => 'development'})
|
41
|
+
expect(g.gemline).to eq(%Q!gem.add_development_dependency "nokogiri", "~> 1.5.5"!)
|
42
|
+
end
|
43
|
+
it "works when passed other groups also" do
|
44
|
+
g = Gemline.new('nokogiri', {:gemspec => true, :group => 'development,test'})
|
45
|
+
expect(g.gemline).to eq(%Q!gem.add_development_dependency "nokogiri", "~> 1.5.5"!)
|
46
|
+
end
|
36
47
|
end
|
37
48
|
|
49
|
+
it "should be able to add options to a gemfile-style gemline" do
|
50
|
+
g = Gemline.new('nokogiri', {:git => "some git repo", :group => [:development, :test]})
|
51
|
+
line = g.gemline
|
52
|
+
expect(line).to start_with(%Q{gem "nokogiri", "~> 1.5.5", })
|
53
|
+
expect(line).to include(%Q{:git => "some git repo"})
|
54
|
+
expect(line).to include(%Q{:group => [:development, :test]})
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
describe 'helper methods' do
|
60
|
+
describe '#options_to_string' do
|
61
|
+
it "returns nothing when no options provided" do
|
62
|
+
expect(Gemline.options_to_string).to eq ''
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "gem groups" do
|
66
|
+
it "handles a single group as a symbol" do
|
67
|
+
expect(Gemline.options_to_string :group => :development).to eq ':group => :development'
|
68
|
+
end
|
69
|
+
|
70
|
+
it "handles a single group as a string" do
|
71
|
+
expect(Gemline.options_to_string :group => 'development').to eq ':group => :development'
|
72
|
+
end
|
73
|
+
|
74
|
+
it "handles a list of groups as symbols" do
|
75
|
+
expect(Gemline.options_to_string :group => [:development, :test]).to eq ':group => [:development, :test]'
|
76
|
+
end
|
77
|
+
|
78
|
+
it "handles a list of groups as strings" do
|
79
|
+
expect(Gemline.options_to_string :group => ['development','test']).to eq ':group => [:development, :test]'
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
38
83
|
end
|
39
84
|
|
40
85
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
if RUBY_VERSION >= '1.9'
|
2
|
+
require 'simplecov'
|
3
|
+
SimpleCov.start do
|
4
|
+
add_filter "/spec/"
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
1
8
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
9
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
10
|
|
@@ -16,7 +23,7 @@ end
|
|
16
23
|
def stub_rubygems_json_output
|
17
24
|
Dir.glob(File.join(File.dirname(__FILE__),'samples', '*.json')).each do |f|
|
18
25
|
gem_name = $1 if f =~ /\/([\w\-]+).json$/
|
19
|
-
Gemline.stub
|
26
|
+
Gemline.stub(:get_rubygem_json).with(gem_name).and_return(IO.read(f))
|
20
27
|
end
|
21
28
|
end
|
22
29
|
|
metadata
CHANGED
@@ -1,96 +1,99 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gemline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.4.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Joseph Alba
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-11-06 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: json_pure
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 1.7.6
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: 1.7.6
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: clipboard
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: 1.0.1
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: 1.0.1
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: ffi
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - '>='
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :runtime
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - '>='
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: rake
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - '>='
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - '>='
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: rspec
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- -
|
73
|
+
- - '>='
|
84
74
|
- !ruby/object:Gem::Version
|
85
|
-
version: 2.
|
75
|
+
version: 2.14.0
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- -
|
80
|
+
- - '>='
|
92
81
|
- !ruby/object:Gem::Version
|
93
|
-
version: 2.
|
82
|
+
version: 2.14.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.7.1
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.7.1
|
94
97
|
description: Grab the latest Gemfile 'gem' line for a specific Ruby gem
|
95
98
|
email:
|
96
99
|
- joe@joealba.com
|
@@ -100,6 +103,7 @@ extensions: []
|
|
100
103
|
extra_rdoc_files: []
|
101
104
|
files:
|
102
105
|
- .gitignore
|
106
|
+
- .rspec
|
103
107
|
- .travis.yml
|
104
108
|
- Gemfile
|
105
109
|
- README.rdoc
|
@@ -116,33 +120,26 @@ files:
|
|
116
120
|
- spec/spec_helper.rb
|
117
121
|
homepage: http://github.com/joealba/gemline
|
118
122
|
licenses: []
|
123
|
+
metadata: {}
|
119
124
|
post_install_message:
|
120
125
|
rdoc_options: []
|
121
126
|
require_paths:
|
122
127
|
- lib
|
123
128
|
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
-
none: false
|
125
129
|
requirements:
|
126
|
-
- -
|
130
|
+
- - '>='
|
127
131
|
- !ruby/object:Gem::Version
|
128
132
|
version: '0'
|
129
|
-
segments:
|
130
|
-
- 0
|
131
|
-
hash: -748514071157106513
|
132
133
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
-
none: false
|
134
134
|
requirements:
|
135
|
-
- -
|
135
|
+
- - '>='
|
136
136
|
- !ruby/object:Gem::Version
|
137
137
|
version: '0'
|
138
|
-
segments:
|
139
|
-
- 0
|
140
|
-
hash: -748514071157106513
|
141
138
|
requirements: []
|
142
139
|
rubyforge_project:
|
143
|
-
rubygems_version: 1.
|
140
|
+
rubygems_version: 2.1.9
|
144
141
|
signing_key:
|
145
|
-
specification_version:
|
142
|
+
specification_version: 4
|
146
143
|
summary: ''
|
147
144
|
test_files:
|
148
145
|
- spec/acceptance_spec.rb
|