gemline 0.4.5 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +1 -1
- data/Rakefile +2 -2
- data/bin/gemline +2 -2
- data/gemline.gemspec +6 -6
- data/lib/gemline/rubygems.rb +12 -0
- data/lib/gemline.rb +36 -37
- data/spec/acceptance_spec.rb +4 -6
- data/spec/gemline_spec.rb +22 -25
- data/spec/spec_helper.rb +5 -5
- metadata +5 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5267ceb6e55d48145e02397d570f6bcba1a2e73c29f482cbbefd5bcfec19032
|
4
|
+
data.tar.gz: 78c7cc5acc3f5bfbbe3d7bfea96bded6193e56e87591794b73a5108c80c9f4c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8199ca68fa9676c2da383c217918b951b16d33be0ff144b6f995fb545d2ffe8e9fe1b71e761e103ea18d831ce8e538fa62aa97d22f469b7c0184ee57e09a9e62
|
7
|
+
data.tar.gz: d473981898b5b6685bd664f8d5d23e3c45622da4b02f3d93ade2ec99741a53b0ac0c6463d26288c8737efefee9f0d15b60b3bfbed6a7b7a7b0758a6767363170
|
data/.github/workflows/tests.yml
CHANGED
data/Rakefile
CHANGED
@@ -6,10 +6,10 @@ require 'rspec/core/rake_task'
|
|
6
6
|
Bundler::GemHelper.install_tasks
|
7
7
|
|
8
8
|
desc 'Default: Run specs'
|
9
|
-
task :
|
9
|
+
task default: :spec
|
10
10
|
|
11
11
|
desc 'Run specs'
|
12
12
|
RSpec::Core::RakeTask.new(:spec)
|
13
13
|
|
14
14
|
desc 'Run specs (alias for Gem Testers)'
|
15
|
-
task :
|
15
|
+
task test: :spec
|
data/bin/gemline
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require "gemline"
|
4
|
-
require
|
4
|
+
require "optparse"
|
5
5
|
|
6
6
|
## TODO: Real command line parsing to support some switches
|
7
7
|
## for things like:
|
@@ -33,7 +33,7 @@ OptionParser.new do |opts|
|
|
33
33
|
end
|
34
34
|
|
35
35
|
opts.on("-v", "--version") do
|
36
|
-
puts "gemline #{Gem::Specification
|
36
|
+
puts "gemline #{Gem::Specification.load("gemline.gemspec").version}"
|
37
37
|
exit
|
38
38
|
end
|
39
39
|
|
data/gemline.gemspec
CHANGED
@@ -3,18 +3,18 @@
|
|
3
3
|
Gem::Specification.new do |gem|
|
4
4
|
gem.authors = ["Joe Alba"]
|
5
5
|
gem.email = ["joe@joealba.com"]
|
6
|
-
gem.description =
|
7
|
-
gem.summary =
|
6
|
+
gem.description = "Grab the latest Gemfile dependency designation for a specific Ruby gem"
|
7
|
+
gem.summary = ""
|
8
8
|
gem.homepage = "https://github.com/joealba/gemline"
|
9
9
|
|
10
|
-
gem.executables = [
|
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
15
|
|
16
|
-
gem.version =
|
17
|
-
gem.license =
|
16
|
+
gem.version = "0.5.0"
|
17
|
+
gem.license = "MIT"
|
18
18
|
|
19
19
|
gem.add_dependency "clipboard", ">= 1.3.5"
|
20
20
|
|
@@ -24,7 +24,7 @@ Gem::Specification.new do |gem|
|
|
24
24
|
gem.add_dependency "ffi"
|
25
25
|
# end
|
26
26
|
|
27
|
-
|
27
|
+
gem.add_development_dependency "rake"
|
28
28
|
gem.add_development_dependency "rspec", ">= 3.0"
|
29
29
|
gem.add_development_dependency "simplecov"
|
30
30
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class Gemline
|
2
|
+
class Rubygems
|
3
|
+
def self.get_rubygem_json(gem_name)
|
4
|
+
uri = URI.parse("https://rubygems.org/api/v1/gems/#{gem_name}.json")
|
5
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
6
|
+
http.use_ssl = true
|
7
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
8
|
+
response = http.request(request)
|
9
|
+
response.body
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/gemline.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "net/https"
|
2
|
+
require "clipboard"
|
3
|
+
require "json"
|
4
|
+
|
5
|
+
require_relative "./gemline/rubygems"
|
4
6
|
|
5
7
|
class Gemline
|
6
8
|
attr_accessor :gem, :gemline, :json, :response
|
@@ -19,69 +21,66 @@ class Gemline
|
|
19
21
|
|
20
22
|
def initialize(gem_name, options = {})
|
21
23
|
@gem = sanitize_gem_name(gem_name)
|
22
|
-
@json = Gemline.get_rubygem_json(@gem)
|
24
|
+
@json = Gemline::Rubygems.get_rubygem_json(@gem)
|
23
25
|
unless gem_not_found?
|
24
26
|
@response = JSON.parse(@json)
|
25
|
-
@gemline = Gemline.create_gemline(@gem, response[
|
27
|
+
@gemline = Gemline.create_gemline(@gem, response["version"], options)
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
29
31
|
def sanitize_gem_name(gem_name)
|
30
|
-
gem_name.to_s.gsub(/[^\w
|
32
|
+
gem_name.to_s.gsub(/[^\w-]+/, "") # Yeah, a little over-defensive.
|
31
33
|
end
|
32
34
|
|
33
35
|
def gem_not_found?
|
34
36
|
!!@json.match(/(could not be found|does not exist)/)
|
35
37
|
end
|
36
38
|
|
37
|
-
|
39
|
+
def self.options_to_string(options = {})
|
40
|
+
if options[:group]
|
41
|
+
options[:group] = [options[:group]].flatten.map(&:to_sym)
|
42
|
+
options[:group] = options[:group].first if options[:group].length == 1
|
43
|
+
end
|
44
|
+
|
45
|
+
options.map { |k, v| "#{k}: #{value_to_string(v)}" }.join(", ")
|
46
|
+
end
|
38
47
|
|
39
|
-
def self.
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
48
|
+
def self.value_to_string(val)
|
49
|
+
case val
|
50
|
+
when Array
|
51
|
+
val.to_s
|
52
|
+
when Symbol
|
53
|
+
":#{val}"
|
54
|
+
when String
|
55
|
+
"\"#{val}\""
|
56
|
+
end
|
46
57
|
end
|
47
58
|
|
48
59
|
def self.create_gemline(gem_name, version, options)
|
49
60
|
if options[:gemspec]
|
50
|
-
|
61
|
+
gemspec_gemline(gem_name, version, options)
|
51
62
|
else
|
52
|
-
|
63
|
+
gemfile_gemline(gem_name, version, options.delete_if { |k, _| k == :gemspec })
|
53
64
|
end
|
54
65
|
end
|
55
66
|
|
56
67
|
def self.gemfile_gemline(gem_name, version, options)
|
57
|
-
|
58
|
-
line << ", " + options_to_string(options) if !options.empty?
|
59
|
-
line
|
68
|
+
%Q{gem "#{gem_name}", "~> #{version}"#{gemfile_gemline_options_suffix(options)}}
|
60
69
|
end
|
61
70
|
|
62
|
-
def self.
|
63
|
-
|
64
|
-
options[:group] = [options[:group]].flatten.map { |x| x.to_sym }
|
65
|
-
options[:group] = options[:group].first if options[:group].length == 1
|
66
|
-
end
|
67
|
-
|
68
|
-
options.inspect.delete('{}').gsub(/(?!\s)=>(?!\s)/, ' => ')
|
71
|
+
def self.gemfile_gemline_options_suffix(options)
|
72
|
+
!options.empty? ? ", " + options_to_string(options) : ""
|
69
73
|
end
|
70
74
|
|
71
75
|
def self.gemspec_gemline(gem_name, version, options)
|
72
|
-
|
73
|
-
|
74
|
-
else
|
75
|
-
%Q{gem.add_dependency "#{gem_name}", "~> #{version}"}
|
76
|
-
end
|
76
|
+
dependency_signifier = options[:group]&.include?('development') ? "add_development_dependency" : "add_dependency"
|
77
|
+
%Q{gem.#{dependency_signifier} "#{gem_name}", "~> #{version}"}
|
77
78
|
end
|
78
79
|
|
79
80
|
def self.copy_to_clipboard(gemline)
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
## Yeah, I hate this too. But it does what I want -- silently fail if Clipboard fails.
|
85
|
-
end
|
81
|
+
Clipboard.copy gemline
|
82
|
+
$stderr.puts " Gem line copied to your clipboard. Ready to paste into your Gemfile"
|
83
|
+
rescue
|
84
|
+
## Yeah, I hate this too. But it does what I want -- silently fail if Clipboard fails.
|
86
85
|
end
|
87
86
|
end
|
data/spec/acceptance_spec.rb
CHANGED
@@ -1,21 +1,19 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "spec_helper"
|
2
|
+
require "stringio"
|
3
3
|
|
4
4
|
describe "gemline output" do
|
5
|
-
|
6
5
|
before do
|
7
6
|
stub_rubygems_json_output
|
8
7
|
end
|
9
8
|
|
10
9
|
it "should output one line to STDOUT so the output can be appended to a Gemfile" do
|
11
|
-
grab_io { Gemline.query(
|
10
|
+
grab_io { Gemline.query("rails") }
|
12
11
|
expect(@stdout.readlines.count).to eq(1)
|
13
12
|
end
|
14
13
|
|
15
14
|
it "should output nothing to STDOUT on error" do
|
16
15
|
allow(Kernel).to receive(:exit).and_return(true)
|
17
|
-
grab_io { Gemline.query(
|
16
|
+
grab_io { Gemline.query("doesnotexist") }
|
18
17
|
expect(@stdout.readlines.count).to eq(0)
|
19
18
|
end
|
20
|
-
|
21
19
|
end
|
data/spec/gemline_spec.rb
CHANGED
@@ -1,82 +1,79 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Gemline do
|
4
|
-
|
5
4
|
describe "querying rubygems" do
|
6
|
-
|
7
5
|
before do
|
8
6
|
stub_rubygems_json_output
|
9
7
|
end
|
10
8
|
|
11
9
|
it "should be able to parse the version out of a good json string" do
|
12
|
-
g = Gemline.new(
|
10
|
+
g = Gemline.new("rails")
|
13
11
|
expect(g.gemline).to eq(%Q{gem "rails", "~> 3.1.1"})
|
14
12
|
end
|
15
13
|
|
16
14
|
it "should whine when the gem you are querying does not exist" do
|
17
|
-
g = Gemline.new(
|
15
|
+
g = Gemline.new("doesnotexist")
|
18
16
|
expect(g.gem_not_found?).to eq true
|
19
17
|
expect(g.gemline).to eq nil
|
20
18
|
end
|
21
19
|
|
22
20
|
it "should properly detect a blocked gem name" do
|
23
|
-
g = Gemline.new(
|
21
|
+
g = Gemline.new("yaml")
|
24
22
|
expect(g.gem_not_found?).to eq true
|
25
23
|
expect(g.gemline).to eq nil
|
26
24
|
end
|
27
25
|
|
28
26
|
it "should properly handle funny characters in the returned JSON" do
|
29
|
-
g = Gemline.new(
|
27
|
+
g = Gemline.new("nokogiri")
|
30
28
|
expect(g.gemline).to eq(%Q{gem "nokogiri", "~> 1.5.5"})
|
31
29
|
end
|
32
30
|
|
33
31
|
it "should be able to generate a gemspec-style gemline" do
|
34
|
-
g = Gemline.new(
|
32
|
+
g = Gemline.new("rails", gemspec: true)
|
35
33
|
expect(g.gemline).to eq(%Q!gem.add_dependency "rails", "~> 3.1.1"!)
|
36
34
|
end
|
37
35
|
|
38
36
|
describe "generates a development gemspec-style gemline" do
|
39
37
|
it "works when just passed the development group" do
|
40
|
-
g = Gemline.new(
|
38
|
+
g = Gemline.new("nokogiri", { gemspec: true, group: "development" })
|
41
39
|
expect(g.gemline).to eq(%Q!gem.add_development_dependency "nokogiri", "~> 1.5.5"!)
|
42
40
|
end
|
43
41
|
it "works when passed other groups also" do
|
44
|
-
g = Gemline.new(
|
42
|
+
g = Gemline.new("nokogiri", { gemspec: true, group: "development,test" })
|
45
43
|
expect(g.gemline).to eq(%Q!gem.add_development_dependency "nokogiri", "~> 1.5.5"!)
|
46
44
|
end
|
47
45
|
end
|
48
46
|
|
49
47
|
it "should be able to add options to a gemfile-style gemline" do
|
50
|
-
g = Gemline.new(
|
48
|
+
g = Gemline.new("nokogiri", { git: "some git repo", group: %i[development test] })
|
51
49
|
line = g.gemline
|
52
50
|
expect(line).to start_with(%Q{gem "nokogiri", "~> 1.5.5", })
|
53
|
-
expect(line).to include(%Q{:
|
54
|
-
expect(line).to include(%Q{:
|
51
|
+
expect(line).to include(%Q{git: "some git repo"})
|
52
|
+
expect(line).to include(%Q{group: [:development, :test]})
|
55
53
|
end
|
56
|
-
|
57
54
|
end
|
58
55
|
|
59
|
-
describe
|
60
|
-
describe
|
56
|
+
describe "helper methods" do
|
57
|
+
describe "#options_to_string" do
|
61
58
|
it "returns nothing when no options provided" do
|
62
|
-
expect(Gemline.options_to_string).to eq
|
59
|
+
expect(Gemline.options_to_string).to eq ""
|
63
60
|
end
|
64
61
|
|
65
62
|
describe "gem groups" do
|
66
|
-
it "handles a single group as a symbol" do
|
67
|
-
expect(Gemline.options_to_string
|
63
|
+
it "handles a single group passed as a symbol" do
|
64
|
+
expect(Gemline.options_to_string(group: :development)).to eq "group: :development"
|
68
65
|
end
|
69
66
|
|
70
|
-
it "handles a single group as a string" do
|
71
|
-
expect(Gemline.options_to_string
|
67
|
+
it "handles a single group passed as a string" do
|
68
|
+
expect(Gemline.options_to_string(group: "development")).to eq "group: :development"
|
72
69
|
end
|
73
70
|
|
74
|
-
it "handles a list of groups as symbols" do
|
75
|
-
expect(Gemline.options_to_string
|
71
|
+
it "handles a list of groups passed as symbols" do
|
72
|
+
expect(Gemline.options_to_string(group: %i[development test])).to eq "group: [:development, :test]"
|
76
73
|
end
|
77
74
|
|
78
|
-
it "handles a list of groups as strings" do
|
79
|
-
expect(Gemline.options_to_string
|
75
|
+
it "handles a list of groups passed as strings" do
|
76
|
+
expect(Gemline.options_to_string(group: %w[development test])).to eq "group: [:development, :test]"
|
80
77
|
end
|
81
78
|
end
|
82
79
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
require
|
1
|
+
require "simplecov"
|
2
2
|
SimpleCov.start do
|
3
3
|
add_filter "/spec/"
|
4
4
|
end
|
5
5
|
|
6
6
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
7
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__),
|
7
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
8
8
|
|
9
|
-
require
|
9
|
+
require "gemline"
|
10
10
|
|
11
11
|
RSpec.configure do |c|
|
12
12
|
# c.mock_with :rr
|
13
13
|
end
|
14
14
|
|
15
15
|
def stub_rubygems_json_output
|
16
|
-
Dir.glob(File.join(File.dirname(__FILE__),
|
16
|
+
Dir.glob(File.join(File.dirname(__FILE__), "samples", "*.json")).each do |f|
|
17
17
|
gem_name = $1 if f =~ /\/([\w\-]+).json$/
|
18
|
-
allow(Gemline).to receive(:get_rubygem_json).with(gem_name).and_return(IO.read(f))
|
18
|
+
allow(Gemline::Rubygems).to receive(:get_rubygem_json).with(gem_name).and_return(IO.read(f))
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gemline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe Alba
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-01-13 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: clipboard
|
@@ -80,7 +79,7 @@ dependencies:
|
|
80
79
|
- - ">="
|
81
80
|
- !ruby/object:Gem::Version
|
82
81
|
version: '0'
|
83
|
-
description: Grab the latest Gemfile
|
82
|
+
description: Grab the latest Gemfile dependency designation for a specific Ruby gem
|
84
83
|
email:
|
85
84
|
- joe@joealba.com
|
86
85
|
executables:
|
@@ -97,6 +96,7 @@ files:
|
|
97
96
|
- bin/gemline
|
98
97
|
- gemline.gemspec
|
99
98
|
- lib/gemline.rb
|
99
|
+
- lib/gemline/rubygems.rb
|
100
100
|
- spec/acceptance_spec.rb
|
101
101
|
- spec/gemline_spec.rb
|
102
102
|
- spec/samples/doesnotexist.json
|
@@ -108,7 +108,6 @@ homepage: https://github.com/joealba/gemline
|
|
108
108
|
licenses:
|
109
109
|
- MIT
|
110
110
|
metadata: {}
|
111
|
-
post_install_message:
|
112
111
|
rdoc_options: []
|
113
112
|
require_paths:
|
114
113
|
- lib
|
@@ -123,8 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
122
|
- !ruby/object:Gem::Version
|
124
123
|
version: '0'
|
125
124
|
requirements: []
|
126
|
-
rubygems_version: 3.
|
127
|
-
signing_key:
|
125
|
+
rubygems_version: 3.6.2
|
128
126
|
specification_version: 4
|
129
127
|
summary: ''
|
130
128
|
test_files:
|