version_gemfile 1.0.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1f2614d58972de1bf90c22e74eb1868ab21072c6f1eb4df96e62a11913ea5192
4
+ data.tar.gz: 6f5d08f9499e94f00e959305ed7129a7d007e843b7931469dead06556890bddd
5
+ SHA512:
6
+ metadata.gz: 628aec628069e5b0f54d24546db4da3312b3cf0d16fc9727efd0a399e9c91a383fc1e8bf02f549e5aacae4e90a1c0beebf7a2a96ec4f66e04a4809b815c4b712
7
+ data.tar.gz: 818828473216383f73cb7f101846364103b99e235f41547039c123d39b724ae325c8e1284f9c6836f4ea0cbd26e8d81acad48c08d0163540ef6e2c98e2e99766
@@ -0,0 +1,16 @@
1
+ # To get started with Dependabot version updates, you'll need to specify which
2
+ # package ecosystems to update and where the package manifests are located.
3
+ # Please see the documentation for all configuration options:
4
+ # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5
+
6
+ version: 2
7
+ updates:
8
+ - package-ecosystem: "bundler"
9
+ directory: "/" # Location of package manifests
10
+ schedule:
11
+ interval: "daily"
12
+
13
+ - package-ecosystem: "github-actions"
14
+ directory: "/" # Location of package manifests
15
+ schedule:
16
+ interval: "daily"
@@ -0,0 +1,31 @@
1
+ name: Running Tests
2
+
3
+ on:
4
+ push:
5
+ branches: [master]
6
+ pull_request:
7
+ branches: [master]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ ruby-version: ["3.0.3"]
15
+
16
+ steps:
17
+ - uses: actions/checkout@v2
18
+
19
+ - name: Set up Ruby
20
+ uses: ruby/setup-ruby@v1
21
+ with:
22
+ ruby-version: ${{ matrix.ruby-version }}
23
+ bundler-cache: true
24
+
25
+ - name: Run tests
26
+ run: bundle exec rake
27
+ env:
28
+ SPEC_OPTS: "-p"
29
+
30
+ - name: Run linter
31
+ run: bundle exec standardrb
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in version_gemfile.gemspec
4
4
  gemspec
data/README.md CHANGED
@@ -33,8 +33,6 @@ Or install it yourself as:
33
33
 
34
34
  Simply type `$ version_gemfile` and you're done.
35
35
 
36
- Also, you should consider the [Add Gem](https://github.com/abuiles/add_gem) gem to add gems to your Gemfile.
37
-
38
36
  ## Contributing
39
37
 
40
38
  1. Fork it
data/Rakefile CHANGED
@@ -1,6 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
- require 'rspec/core/rake_task'
2
+ require "rspec/core/rake_task"
3
+ require "standard/rake"
3
4
 
4
5
  RSpec::Core::RakeTask.new(:spec)
5
6
 
6
- task :default => :spec
7
+ task default: [:spec, "standard:fix"]
data/bin/version_gemfile CHANGED
@@ -8,11 +8,19 @@ options = {}
8
8
  opt_parser = OptionParser.new do |opts|
9
9
  opts.banner = "Usage: version_gemfile [options]"
10
10
 
11
- opts.on("-g", "--gemfile", "Gemfile path") do |path|
11
+ opts.on("-g", "--gemfile STRING", "Gemfile path") do |path|
12
12
  options[:gemfile] = path
13
13
  end
14
+
15
+ opts.on("-l", "--gemfile-lock STRING", "Gemfile.lock path") do |path|
16
+ options[:gemfile_lock] = path
17
+ end
18
+
19
+ opts.on("-q", "--gem-command-quote STRING", "Gem command quote") do |quote|
20
+ options[:gem_command_quote] = quote
21
+ end
14
22
  end
15
23
 
16
24
  opt_parser.parse!
17
25
 
18
- VersionGemfile::Versioner.add_versions!(options)
26
+ VersionGemfile::Versioner.add_versions!(options)
@@ -1,3 +1,3 @@
1
1
  module VersionGemfile
2
- VERSION = "1.0.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -1,14 +1,16 @@
1
- require 'tempfile'
1
+ require "tempfile"
2
2
 
3
3
  module VersionGemfile
4
4
  class Versioner
5
5
  attr_reader :lock_contents, :gemfile_content, :options, :lockfile_path,
6
- :gemfile_path
6
+ :gemfile_path, :gem_command_quote
7
7
 
8
8
  IS_GEM_LINE = /^\s* gem \s+ ['|"] /ix
9
- HAS_VERSION = /^\s*gem \s+ ['|"] \s* [\w|-]+ \s* ['|"]\s*,\s*['|"]/ix
9
+ HAS_VERSION = /^\s*gem \s+ ['|"] \s* [\w|-]+ \s* ['|"]\s*,\s*['|"]/ix
10
10
  GET_GEM_NAME = /^\s*gem \s+ ['|"] \s* ([\w|-]+) \s* ['|"]/ix
11
- GET_VERSION_NUMBER = /^\s+[\w|-]+ \s \( ([\w|\.]+) \)/ix
11
+ GET_VERSION_NUMBER = /^\s+[\w|-]+ \s \( ([\w|.]+) \)/ix
12
+
13
+ DEFAULT_GEM_COMMAND_QUOTE = '"'.freeze
12
14
 
13
15
  def self.add_versions!(options = {})
14
16
  new(options).add_versions
@@ -16,15 +18,15 @@ module VersionGemfile
16
18
 
17
19
  def initialize(options = {})
18
20
  @options = normalize_hash(options.clone)
19
- @gemfile_path = @options.fetch('gemfile'){ 'Gemfile' }
20
- @lockfile_path = "#{@gemfile_path}.lock"
21
-
22
- @lock_contents = File.read(lockfile_path)
21
+ @gemfile_path = @options.fetch("gemfile") { "Gemfile" }
22
+ @lockfile_path = @options.fetch("gemfile_lock") { "#{@gemfile_path}.lock" }
23
+ @gem_command_quote = @options.fetch("gem_command_quote") { DEFAULT_GEM_COMMAND_QUOTE }
24
+ @lock_contents = File.read(lockfile_path)
23
25
  @gemfile_content = File.readlines(gemfile_path)
24
26
  @orig_gemfile = File.read(gemfile_path)
25
27
  end
26
28
 
27
- #TODO: Clean this up!
29
+ # TODO: Clean this up!
28
30
  def add_versions
29
31
  new_gemfile = Tempfile.new("Gemfile.versioned")
30
32
  begin
@@ -37,11 +39,11 @@ module VersionGemfile
37
39
  end
38
40
  File.truncate(gemfile_path, 0)
39
41
  new_gemfile.rewind
40
- File.open(gemfile_path, "w") {|f| f.write(new_gemfile.read)}
41
- rescue Exception => e
42
+ File.write(gemfile_path, new_gemfile.read)
43
+ rescue => e
42
44
  puts "ERROR: #{e}"
43
45
  puts "Restoring Gemfile at #{gemfile_path}"
44
- File.open(gemfile_path, "w") {|f| f.write(@orig_gemfile)}
46
+ File.write(gemfile_path, @orig_gemfile)
45
47
  ensure
46
48
  new_gemfile.close
47
49
  new_gemfile.unlink
@@ -52,22 +54,37 @@ module VersionGemfile
52
54
  gem_line.match(HAS_VERSION)
53
55
  end
54
56
 
57
+ def build_gem_line(gem_line)
58
+ return gem_line if gem_line.match(HAS_VERSION)
59
+
60
+ name = gem_name(gem_line)
61
+ version = get_version(name)
62
+
63
+ return gem_line unless version
64
+
65
+ options = gem_line.gsub(GET_GEM_NAME, "").strip
66
+
67
+ quote = gem_command_quote || DEFAULT_GEM_COMMAND_QUOTE
68
+
69
+ "#{spaces(gem_line)}gem #{quote}#{name}#{quote}, #{quote}~> #{version}#{quote}#{options}"
70
+ end
71
+
72
+ private
73
+
55
74
  def is_gem_line?(gem_line)
56
75
  gem_line =~ IS_GEM_LINE
57
76
  end
58
77
 
59
- def build_gem_line(gem_line, version = nil)
60
- return gem_line if gem_line.match(HAS_VERSION)
61
- gem_name = gem_line.match(GET_GEM_NAME) { $1 }
62
- spaces = gem_line.match(/^(\s+)/){ $1 }
63
- version ||= get_version(gem_name)
64
- "#{spaces}gem '#{gem_name}', '~> #{version}'"
78
+ def gem_name(gem_line)
79
+ gem_line.match(GET_GEM_NAME) { $1 }
65
80
  end
66
81
 
67
- private
82
+ def spaces(gem_line)
83
+ gem_line.match(/^(\s+)/) { $1 }
84
+ end
68
85
 
69
86
  def get_version(gem_name)
70
- regexp = /^\s+#{gem_name}\s\(([\w|\.]+)\)/ix
87
+ regexp = /^\s+#{gem_name}\s\(([\w|.]+)\)/ix
71
88
  regexp.match(lock_contents) { $1 }
72
89
  end
73
90
 
@@ -80,4 +97,4 @@ module VersionGemfile
80
97
  hash
81
98
  end
82
99
  end
83
- end
100
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,5 @@
1
- require 'bundler'
2
- require 'version_gemfile'
1
+ require "bundler"
2
+ require "version_gemfile"
3
3
 
4
4
  Bundler.require(:default, :test, :development)
5
5
 
@@ -28,7 +28,6 @@ module SpecHelpers
28
28
  support_file_lines "Gemfile.initial.test"
29
29
  end
30
30
  end
31
-
32
31
 
33
32
  RSpec.configure do |config|
34
33
  config.expect_with :rspec do |c|
@@ -1,27 +1,28 @@
1
- source 'http://rubygems.org'
2
- ruby '1.9.3'
1
+ source "http://rubygems.org"
2
+ ruby "1.9.3"
3
3
 
4
- gem 'rails', '3.2.8'
5
- gem 'pg', '~> 0.14.1'
6
- gem 'nokogiri', '~> 1.5.5'
7
- gem 'jquery-rails', '~> 2.1.3'
8
- gem 'airbrake', '~> 3.1.6'
9
- gem 'devise', '~> 2.1.2'
4
+ gem "rails", "3.2.8"
5
+ gem "pg", "~> 0.14.1"
6
+ gem "nokogiri", "~> 1.5.5"
7
+ gem "jquery-rails", "~> 2.1.3"
8
+ gem "airbrake", "~> 3.1.6"
9
+ gem "devise", "~> 2.1.2"
10
10
  gem "twitter-bootstrap-rails", "2.1.4"
11
- gem 'friendly_id', '~> 4.0.8'
12
- gem 'redcarpet', '~> 2.2.2'
13
- gem 'rack-timeout', '~> 0.0.3'
14
- gem 'mixpanel', '~> 3.0.2'
11
+ gem "friendly_id", "~> 4.0.8"
12
+ gem "redcarpet", "~> 2.2.2"
13
+ gem "rack-timeout", "~> 0.0.3"
14
+ gem "mixpanel", "~> 3.0.2"
15
15
  gem "rails3_acts_as_paranoid", "~> 0.2.0"
16
16
 
17
17
 
18
18
  group :development, :test do
19
- gem 'rspec-rails', '~> 2.11.4'
20
- gem 'factory_girl_rails', '~> 4.1.0'
19
+ gem "rspec-rails", "~> 2.11.4"
20
+ gem "factory_girl_rails", "~> 4.1.0"
21
21
  end
22
22
 
23
23
  group :assets do
24
- gem 'sass-rails', '~> 3.2.3'
25
- gem 'uglifier', '>= 1.0.3'
24
+ gem "sass-rails", "~> 3.2.3"
25
+ gem "uglifier", ">= 1.0.3"
26
26
  end
27
27
 
28
+ gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw, :jruby]
@@ -1,10 +1,10 @@
1
- source 'http://rubygems.org'
2
- ruby '1.9.3'
1
+ source "http://rubygems.org"
2
+ ruby "1.9.3"
3
3
 
4
- gem 'rails', '3.2.8'
4
+ gem "rails", "3.2.8"
5
5
  gem "pg"
6
6
  gem "nokogiri"
7
- gem 'jquery-rails'
7
+ gem "jquery-rails"
8
8
  gem "airbrake"
9
9
  gem "devise"
10
10
  gem "twitter-bootstrap-rails", "2.1.4"
@@ -21,7 +21,8 @@ group :development, :test do
21
21
  end
22
22
 
23
23
  group :assets do
24
- gem 'sass-rails', '~> 3.2.3'
25
- gem 'uglifier', '>= 1.0.3'
24
+ gem "sass-rails", "~> 3.2.3"
25
+ gem "uglifier", ">= 1.0.3"
26
26
  end
27
27
 
28
+ gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw, :jruby]
@@ -1,27 +1,28 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  module VersionGemfile
4
4
  describe Versioner do
5
-
6
5
  describe "#build_gem_line" do
7
6
  let(:versioner) { Versioner.new }
7
+ before { versioner.stub(lock_contents: test_gemfile_lock) }
8
8
 
9
9
  it "adds a pessimistic version to the gem" do
10
- expect(versioner.build_gem_line("gem 'rails'", "45.3.2")).to eql("gem 'rails', '~> 45.3.2'")
11
- expect(versioner.build_gem_line('gem "rails"', "45.3.2")).to eql("gem 'rails', '~> 45.3.2'")
12
- expect(versioner.build_gem_line('gem "rack-cache"', "5.3.2")).to eql("gem 'rack-cache', '~> 5.3.2'")
10
+ expect(versioner.build_gem_line("gem 'rails'")).to match(/~>/)
13
11
  end
14
12
 
15
13
  it "adds the version from the Gemfile.lock file" do
16
- versioner.stub(lock_contents: test_gemfile_lock)
17
- expect(versioner.build_gem_line "gem 'pg'" ).to eql("gem 'pg', '~> 0.14.1'")
14
+ expect(versioner.build_gem_line("gem 'pg'")).to eql('gem "pg", "~> 0.14.1"')
15
+ expect(versioner.build_gem_line("gem 'pg', :require => 'hello'")).to eql('gem "pg", "~> 0.14.1", :require => \'hello\'')
16
+ expect(versioner.build_gem_line("gem 'pg', require: 'hello'")).to eql('gem "pg", "~> 0.14.1", require: \'hello\'')
18
17
  end
19
18
  end
20
19
 
21
20
  describe "#add_versions" do
22
- let(:options) {{
23
- gemfile: File.join(support_dir_path, "Gemfile.initial.test")
24
- }}
21
+ let(:options) {
22
+ {
23
+ gemfile: File.join(support_dir_path, "Gemfile.initial.test")
24
+ }
25
+ }
25
26
 
26
27
  let(:versioner) { Versioner.new(options) }
27
28
 
@@ -32,7 +33,7 @@ module VersionGemfile
32
33
  end
33
34
 
34
35
  after do
35
- File.open(options[:gemfile], "w"){|f| f.write(@original_gemfile)}
36
+ File.write(options[:gemfile], @original_gemfile)
36
37
  end
37
38
 
38
39
  it "adds versions to the gemfile" do
@@ -56,7 +57,7 @@ module VersionGemfile
56
57
  GEMS
57
58
 
58
59
  gems.split("\n").each do |gem_name|
59
- expect(matcher.match_gem(gem_name)).to be_true
60
+ expect(matcher.match_gem(gem_name)).to be_truthy
60
61
  end
61
62
  end
62
63
 
@@ -68,9 +69,9 @@ module VersionGemfile
68
69
  GEMS
69
70
 
70
71
  gems.split("\n").each do |gem_name|
71
- expect(matcher.match_gem(gem_name)).to be_false
72
+ expect(matcher.match_gem(gem_name)).to be_falsey
72
73
  end
73
74
  end
74
75
  end
75
76
  end
76
- end
77
+ end
@@ -1,5 +1,4 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe VersionGemfile do
4
-
5
4
  end
@@ -1,22 +1,22 @@
1
- # -*- encoding: utf-8 -*-
2
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path("../lib", __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'version_gemfile/version'
3
+ require "version_gemfile/version"
5
4
 
6
5
  Gem::Specification.new do |gem|
7
- gem.name = "version_gemfile"
8
- gem.version = VersionGemfile::VERSION
9
- gem.authors = ["Nicolás Hock Isaza"]
10
- gem.email = ["nhocki@gmail.com"]
11
- gem.description = %q{Tool to add version to your Gemfile's gems.}
12
- gem.summary = %q{Prevent future problems dude. Add the versions and move on.}
13
- gem.homepage = ""
6
+ gem.name = "version_gemfile"
7
+ gem.version = VersionGemfile::VERSION
8
+ gem.authors = ["Nicolás Hock Isaza"]
9
+ gem.email = ["nhocki@gmail.com"]
10
+ gem.description = "Tool to add version to your Gemfile's gems."
11
+ gem.summary = "Prevent future problems dude. Add the versions and move on."
12
+ gem.homepage = ""
14
13
 
15
- gem.files = `git ls-files`.split($/)
16
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.files = `git ls-files`.split($/)
15
+ gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
17
  gem.require_paths = ["lib"]
19
18
 
20
- gem.add_development_dependency('rake', '~> 10.0.3')
21
- gem.add_development_dependency('rspec', '~> 2.12.0')
19
+ gem.add_development_dependency("rake", "~> 13.0.6")
20
+ gem.add_development_dependency("rspec", "~> 3.10.0")
21
+ gem.add_development_dependency("standard", "~> 1.7.0")
22
22
  end
metadata CHANGED
@@ -1,48 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: version_gemfile
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
5
- prerelease:
4
+ version: 1.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Nicolás Hock Isaza
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-01-16 00:00:00.000000000 Z
11
+ date: 2022-02-02 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
- version: 10.0.3
19
+ version: 13.0.6
22
20
  type: :development
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
- version: 10.0.3
26
+ version: 13.0.6
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
- version: 2.12.0
33
+ version: 3.10.0
38
34
  type: :development
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
- version: 2.12.0
40
+ version: 3.10.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: standard
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.7.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.7.0
46
55
  description: Tool to add version to your Gemfile's gems.
47
56
  email:
48
57
  - nhocki@gmail.com
@@ -51,8 +60,9 @@ executables:
51
60
  extensions: []
52
61
  extra_rdoc_files: []
53
62
  files:
54
- - .gitignore
55
- - .travis.yml
63
+ - ".github/dependabot.yml"
64
+ - ".github/workflows/ruby.yml"
65
+ - ".gitignore"
56
66
  - Gemfile
57
67
  - LICENSE.txt
58
68
  - README.md
@@ -70,33 +80,25 @@ files:
70
80
  - version_gemfile.gemspec
71
81
  homepage: ''
72
82
  licenses: []
73
- post_install_message:
83
+ metadata: {}
84
+ post_install_message:
74
85
  rdoc_options: []
75
86
  require_paths:
76
87
  - lib
77
88
  required_ruby_version: !ruby/object:Gem::Requirement
78
- none: false
79
89
  requirements:
80
- - - ! '>='
90
+ - - ">="
81
91
  - !ruby/object:Gem::Version
82
92
  version: '0'
83
- segments:
84
- - 0
85
- hash: 2288187485407978392
86
93
  required_rubygems_version: !ruby/object:Gem::Requirement
87
- none: false
88
94
  requirements:
89
- - - ! '>='
95
+ - - ">="
90
96
  - !ruby/object:Gem::Version
91
97
  version: '0'
92
- segments:
93
- - 0
94
- hash: 2288187485407978392
95
98
  requirements: []
96
- rubyforge_project:
97
- rubygems_version: 1.8.23
98
- signing_key:
99
- specification_version: 3
99
+ rubygems_version: 3.2.32
100
+ signing_key:
101
+ specification_version: 4
100
102
  summary: Prevent future problems dude. Add the versions and move on.
101
103
  test_files:
102
104
  - spec/spec_helper.rb
data/.travis.yml DELETED
@@ -1,8 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 1.9.3
4
- - 1.9.2
5
- - jruby-19mode
6
- - rbx-19mode
7
- - ruby-head
8
- - jruby-head