gemline 0.4.4 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 742ba3f7b6e6f8c491852c705d2236c660e290e1
4
- data.tar.gz: 4c37e3b817a1b70cf4729fdde93971cb9e6b9e5e
2
+ SHA256:
3
+ metadata.gz: a5267ceb6e55d48145e02397d570f6bcba1a2e73c29f482cbbefd5bcfec19032
4
+ data.tar.gz: 78c7cc5acc3f5bfbbe3d7bfea96bded6193e56e87591794b73a5108c80c9f4c4
5
5
  SHA512:
6
- metadata.gz: 167098e6467eb8f334de634f43669e740db75a941a8ff4fd15aca1f8d6cb7a8fb076fb355dd85d4fe1daeaf208583712d566cb4bed7bf314a939818e16bb3d0d
7
- data.tar.gz: d36d9034de9bd6ec703bbe3cc0d88b787db76fe7cbe84472fc4ff84c555b9579fdba7921af300432fe2b9b5d780707c83418f906f42aff619b9a7dc86227a1d6
6
+ metadata.gz: 8199ca68fa9676c2da383c217918b951b16d33be0ff144b6f995fb545d2ffe8e9fe1b71e761e103ea18d831ce8e538fa62aa97d22f469b7c0184ee57e09a9e62
7
+ data.tar.gz: d473981898b5b6685bd664f8d5d23e3c45622da4b02f3d93ade2ec99741a53b0ac0c6463d26288c8737efefee9f0d15b60b3bfbed6a7b7a7b0758a6767363170
@@ -0,0 +1,32 @@
1
+ name: Ruby CI
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ paths-ignore:
8
+ - 'README.rdoc'
9
+ pull_request:
10
+ branches:
11
+ - main
12
+ paths-ignore:
13
+ - 'README.rdoc'
14
+ jobs:
15
+ test:
16
+ runs-on: ubuntu-latest
17
+ if: "contains(github.event.commits[0].message, '[ci skip]') == false"
18
+
19
+ strategy:
20
+ matrix:
21
+ ruby: [3.4.1, 3.3.6, 3.2.6, 2.7.8]
22
+
23
+ steps:
24
+ - name: Checkout
25
+ uses: actions/checkout@v2
26
+ - name: Setup Ruby
27
+ uses: ruby/setup-ruby@v1
28
+ with:
29
+ ruby-version: ${{ matrix.ruby }}
30
+ bundler-cache: true
31
+ - name: Test
32
+ run: bundle exec rake spec
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 :default => :spec
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 :test => :spec
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 'optparse'
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::load("gemline.gemspec").version}"
36
+ puts "gemline #{Gem::Specification.load("gemline.gemspec").version}"
37
37
  exit
38
38
  end
39
39
 
data/gemline.gemspec CHANGED
@@ -3,20 +3,20 @@
3
3
  Gem::Specification.new do |gem|
4
4
  gem.authors = ["Joe Alba"]
5
5
  gem.email = ["joe@joealba.com"]
6
- gem.description = %q{Grab the latest Gemfile 'gem' line for a specific Ruby gem}
7
- gem.summary = %q{}
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 = ['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
15
 
16
- gem.version = '0.4.4'
17
- gem.license = 'MIT'
16
+ gem.version = "0.5.0"
17
+ gem.license = "MIT"
18
18
 
19
- gem.add_dependency "clipboard", ">= 1.0.1"
19
+ gem.add_dependency "clipboard", ">= 1.3.5"
20
20
 
21
21
  # if RUBY_PLATFORM =~ /(win|w)32$/
22
22
  ## The clipboard gem doesn't do a platform-dependent check,
@@ -24,7 +24,7 @@ Gem::Specification.new do |gem|
24
24
  gem.add_dependency "ffi"
25
25
  # end
26
26
 
27
- gem.add_development_dependency "rake" # For Travis CI
28
- gem.add_development_dependency "rspec", ">= 3.3.0"
29
- gem.add_development_dependency "simplecov", ">= 0.7.1"
27
+ gem.add_development_dependency "rake"
28
+ gem.add_development_dependency "rspec", ">= 3.0"
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 'net/https'
2
- require 'clipboard'
3
- require 'json'
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,71 +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['version'], options)
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\-]+/,'') # Yeah, a little over-defensive.
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
 
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
37
44
 
38
- private
45
+ options.map { |k, v| "#{k}: #{value_to_string(v)}" }.join(", ")
46
+ end
39
47
 
40
- def self.get_rubygem_json(gem_name)
41
- uri = URI.parse("https://rubygems.org/api/v1/gems/#{gem_name}.json")
42
- http = Net::HTTP.new(uri.host, uri.port)
43
- http.use_ssl = true
44
- # http.verify_mode = OpenSSL::SSL::VERIFY_NONE
45
- request = Net::HTTP::Get.new(uri.request_uri)
46
- response = http.request(request)
47
- response.body
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
48
57
  end
49
58
 
50
59
  def self.create_gemline(gem_name, version, options)
51
60
  if options[:gemspec]
52
- return gemspec_gemline(gem_name, version, options)
61
+ gemspec_gemline(gem_name, version, options)
53
62
  else
54
- return gemfile_gemline(gem_name, version, options.delete_if {|k,v| k == :gemspec})
63
+ gemfile_gemline(gem_name, version, options.delete_if { |k, _| k == :gemspec })
55
64
  end
56
65
  end
57
66
 
58
67
  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
68
+ %Q{gem "#{gem_name}", "~> #{version}"#{gemfile_gemline_options_suffix(options)}}
62
69
  end
63
70
 
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)/, ' => ')
71
+ def self.gemfile_gemline_options_suffix(options)
72
+ !options.empty? ? ", " + options_to_string(options) : ""
70
73
  end
71
74
 
72
75
  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}"}
77
- end
76
+ dependency_signifier = options[:group]&.include?('development') ? "add_development_dependency" : "add_dependency"
77
+ %Q{gem.#{dependency_signifier} "#{gem_name}", "~> #{version}"}
78
78
  end
79
79
 
80
80
  def self.copy_to_clipboard(gemline)
81
- begin
82
- Clipboard.copy gemline
83
- $stderr.puts " Gem line copied to your clipboard. Ready to paste into your Gemfile"
84
- rescue
85
- ## Yeah, I hate this too. But it does what I want -- silently fail if Clipboard fails.
86
- 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.
87
85
  end
88
-
89
86
  end
@@ -1,21 +1,19 @@
1
- require 'spec_helper'
2
- require 'stringio'
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('rails') }
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('doesnotexist') }
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 'spec_helper'
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('rails')
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('doesnotexist')
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('yaml')
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('nokogiri')
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('rails', :gemspec => true)
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('nokogiri', {:gemspec => true, :group => 'development'})
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('nokogiri', {:gemspec => true, :group => 'development,test'})
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('nokogiri', {:git => "some git repo", :group => [:development, :test]})
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{:git => "some git repo"})
54
- expect(line).to include(%Q{:group => [:development, :test]})
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 'helper methods' do
60
- describe '#options_to_string' do
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 :group => :development).to eq ':group => :development'
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 :group => 'development').to eq ':group => :development'
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 :group => [:development, :test]).to eq ':group => [:development, :test]'
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 :group => ['development','test']).to eq ':group => [:development, :test]'
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,29 +1,21 @@
1
- if RUBY_VERSION >= '1.9'
2
- require 'simplecov'
3
- SimpleCov.start do
4
- add_filter "/spec/"
5
- end
1
+ require "simplecov"
2
+ SimpleCov.start do
3
+ add_filter "/spec/"
6
4
  end
7
5
 
8
6
  $LOAD_PATH.unshift(File.dirname(__FILE__))
9
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
10
-
11
- require 'rubygems'
12
- require 'gemline'
13
-
14
- require 'bundler'
15
- Bundler.setup
7
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
16
8
 
9
+ require "gemline"
17
10
 
18
11
  RSpec.configure do |c|
19
12
  # c.mock_with :rr
20
13
  end
21
14
 
22
-
23
15
  def stub_rubygems_json_output
24
- Dir.glob(File.join(File.dirname(__FILE__),'samples', '*.json')).each do |f|
16
+ Dir.glob(File.join(File.dirname(__FILE__), "samples", "*.json")).each do |f|
25
17
  gem_name = $1 if f =~ /\/([\w\-]+).json$/
26
- 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))
27
19
  end
28
20
  end
29
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.4
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: 2015-12-21 00:00:00.000000000 Z
10
+ date: 2025-01-13 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: clipboard
@@ -16,14 +15,14 @@ dependencies:
16
15
  requirements:
17
16
  - - ">="
18
17
  - !ruby/object:Gem::Version
19
- version: 1.0.1
18
+ version: 1.3.5
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
23
  - - ">="
25
24
  - !ruby/object:Gem::Version
26
- version: 1.0.1
25
+ version: 1.3.5
27
26
  - !ruby/object:Gem::Dependency
28
27
  name: ffi
29
28
  requirement: !ruby/object:Gem::Requirement
@@ -58,29 +57,29 @@ dependencies:
58
57
  requirements:
59
58
  - - ">="
60
59
  - !ruby/object:Gem::Version
61
- version: 3.3.0
60
+ version: '3.0'
62
61
  type: :development
63
62
  prerelease: false
64
63
  version_requirements: !ruby/object:Gem::Requirement
65
64
  requirements:
66
65
  - - ">="
67
66
  - !ruby/object:Gem::Version
68
- version: 3.3.0
67
+ version: '3.0'
69
68
  - !ruby/object:Gem::Dependency
70
69
  name: simplecov
71
70
  requirement: !ruby/object:Gem::Requirement
72
71
  requirements:
73
72
  - - ">="
74
73
  - !ruby/object:Gem::Version
75
- version: 0.7.1
74
+ version: '0'
76
75
  type: :development
77
76
  prerelease: false
78
77
  version_requirements: !ruby/object:Gem::Requirement
79
78
  requirements:
80
79
  - - ">="
81
80
  - !ruby/object:Gem::Version
82
- version: 0.7.1
83
- description: Grab the latest Gemfile 'gem' line for a specific Ruby gem
81
+ version: '0'
82
+ description: Grab the latest Gemfile dependency designation for a specific Ruby gem
84
83
  email:
85
84
  - joe@joealba.com
86
85
  executables:
@@ -88,15 +87,16 @@ executables:
88
87
  extensions: []
89
88
  extra_rdoc_files: []
90
89
  files:
90
+ - ".github/workflows/tests.yml"
91
91
  - ".gitignore"
92
92
  - ".rspec"
93
- - ".travis.yml"
94
93
  - Gemfile
95
94
  - README.rdoc
96
95
  - Rakefile
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,9 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
122
  - !ruby/object:Gem::Version
124
123
  version: '0'
125
124
  requirements: []
126
- rubyforge_project:
127
- rubygems_version: 2.4.8
128
- signing_key:
125
+ rubygems_version: 3.6.2
129
126
  specification_version: 4
130
127
  summary: ''
131
128
  test_files:
data/.travis.yml DELETED
@@ -1,6 +0,0 @@
1
- rvm:
2
- - 1.9.3
3
- - 2.1.8
4
- - 2.2.4
5
- - jruby-19mode
6
- - ruby-head