gemfile_locker 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9275a777c8aafc2e556cc83325de9ba87e35c0bc
4
+ data.tar.gz: 343d049443e580a7eb6de5164e38d4597168bd05
5
+ SHA512:
6
+ metadata.gz: ff456f46c6bcf7a33eb84faffd600284df75c74e53cab75d432e14bb6cd86906f1aa31fe6392ff74848518c077d425244038da2ab8db43803d0e3bf2c666ed9c
7
+ data.tar.gz: 8f74a681efee7ea0a963fdbbb90aed3c917fcf9e322990d4dd845f6b310ff7ccb0badcbd2f66ce4dbf3dff84a6dd34bc7a186d92c1f4eada2acf9e6c411b0902
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,32 @@
1
+ AllCops:
2
+ Exclude:
3
+ - tmp/**/*
4
+ - spec/fixtures/*
5
+
6
+ Style/Alias: {Enabled: false}
7
+ Style/AlignParameters:
8
+ # Disable, till rubocop supports combination of styles.
9
+ # Use one of this styles where appropriate, keep it clean, compact and readable.
10
+ Enabled: false
11
+ # EnforcedStyle:
12
+ # - with_first_parameter
13
+ # - with_fixed_indentation
14
+ Style/AndOr: {EnforcedStyle: conditionals}
15
+ Style/ClosingParenthesisIndentation: {Enabled: false}
16
+ Style/Documentation: {Enabled: false}
17
+ Style/DotPosition: {EnforcedStyle: trailing}
18
+ Style/FirstParameterIndentation: {EnforcedStyle: consistent}
19
+ Style/IfUnlessModifier: {Enabled: false}
20
+ Style/ModuleFunction: {Enabled: false}
21
+ Style/MultilineOperationIndentation: {EnforcedStyle: indented}
22
+ Style/NestedParenthesizedCalls: {Enabled: false}
23
+ Style/PredicateName: {Enabled: false}
24
+ Style/SignalException: {EnforcedStyle: only_raise}
25
+ Style/SpaceInsideHashLiteralBraces: {EnforcedStyle: no_space}
26
+ Style/TrailingCommaInArguments: {Enabled: false}
27
+ Style/TrailingCommaInLiteral: {EnforcedStyleForMultiline: comma}
28
+
29
+ Metrics/AbcSize: {Max: 21}
30
+ Metrics/LineLength: {Max: 100}
31
+ Metrics/MethodLength: {Max: 30}
32
+ Metrics/CyclomaticComplexity: {Max: 8}
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ sudo: false
2
+ cache: bundler
3
+ language: ruby
4
+ rvm:
5
+ - 2.3.0
6
+ before_install: gem install bundler -v 1.13.6
7
+ notifications:
8
+ email: false
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gemfile_locker.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'sdoc', '~> 0.4.1'
8
+ gem 'pry', '~> 0.10.1'
9
+ gem 'pry-byebug', '~> 3.2.0'
10
+
11
+ gem 'rspec', '~> 3.5.0'
12
+ gem 'rspec-its', '~> 1.1.0'
13
+ gem 'aruba', '~> 0.14.2'
14
+
15
+ gem 'rubocop', '~> 0.37.0'
16
+
17
+ gem 'coveralls', '~> 0.8.2'
18
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Max Melentiev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # GemfileLocker
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/gemfile_locker.svg)](http://badge.fury.io/rb/gemfile_locker)
4
+ [![Code Climate](https://codeclimate.com/github/printercu/gemfile_locker/badges/gpa.svg)](https://codeclimate.com/github/printercu/gemfile_locker)
5
+ [![Build Status](https://travis-ci.org/printercu/gemfile_locker.svg)](https://travis-ci.org/printercu/gemfile_locker)
6
+
7
+ Tool to manage Gemfile. Lock and unlock all dependencies for safe `bundle update`.
8
+
9
+ GemfileLocker can lock all dependencies strictly or semi-strictly (with `~>`),
10
+ so it gets safe to run `bundle update` anytime.
11
+
12
+ It can also unlock all dependencies so you can easily update to the latest versions.
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'gemfile_locker'
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ $ bundle
25
+
26
+ Or install it yourself as:
27
+
28
+ $ gem install gemfile_locker
29
+
30
+ ## Usage
31
+
32
+ ```
33
+ gemfile_locker help
34
+
35
+ gemfile_locker lock # Lock all missing versions
36
+
37
+ Options:
38
+ --loose/-l [full|patch|minor|major] # Lock with ~>
39
+ --force/-f # Lock all gems
40
+ --skip/-s # Skip this gems
41
+ --only/-o # Lock only this gems
42
+
43
+ gemfile_locker unlock # unlock all
44
+
45
+ Options:
46
+ --skip/-s # Skip this gems
47
+ --only/-o # Unlock only this gems
48
+ ```
49
+
50
+ ## Development
51
+
52
+ After checking out the repo, run `bin/setup` to install dependencies.
53
+ Then, run `rake spec` to run the tests.
54
+ You can also run `bin/console` for an interactive prompt that will allow you to experiment.
55
+
56
+ To install this gem onto your local machine, run `bundle exec rake install`.
57
+ To release a new version, update the version number in `version.rb`,
58
+ and then run `bundle exec rake release`, which will create a git tag for the version,
59
+ push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
60
+
61
+ ## Contributing
62
+
63
+ Bug reports and pull requests are welcome on GitHub at https://github.com/printercu/gemfile_locker.
64
+
65
+ ## License
66
+
67
+ MIT
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
7
+
8
+ require 'sdoc'
9
+ RDoc::Task.new(:doc) do |rdoc|
10
+ rdoc.rdoc_dir = 'doc'
11
+
12
+ rdoc.title = 'RailsStuff'
13
+
14
+ rdoc.options << '--markup' << 'markdown'
15
+ rdoc.options << '-e' << 'UTF-8'
16
+ rdoc.options << '--format' << 'sdoc'
17
+ rdoc.options << '--template' << 'rails'
18
+ rdoc.options << '--all'
19
+
20
+ rdoc.rdoc_files.include('README.md')
21
+ rdoc.rdoc_files.include('lib/**/*.rb')
22
+ end
data/bin/console ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'gemfile_locker'
5
+
6
+ require 'pry'
7
+ Pry.start
@@ -0,0 +1,14 @@
1
+ #!/bin/bash
2
+
3
+ pattern=$(echo -n '\.rb
4
+ \.gemspec
5
+ \.jbuilder
6
+ \.rake
7
+ config\.ru
8
+ Gemfile
9
+ Rakefile' | tr "\\n" '|')
10
+
11
+ files=`git diff --cached --name-status | grep -E "^[AM].*($pattern)$" | cut -f2-`
12
+ if [ -n "$files" ]; then
13
+ bundle exec rubocop $files --force-exclusion
14
+ fi
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ root = File.expand_path('../../', __FILE__)
4
+ hooks_dir = "#{root}/bin/git-hooks"
5
+
6
+ `ls -1 #{hooks_dir}`.each_line.map(&:strip).each do |file|
7
+ `ln -sf #{hooks_dir}/#{file} #{root}/.git/hooks/#{file}`
8
+ end
data/bin/setup ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
9
+ bin/install_git_hooks
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'gemfile_locker'
4
+ GemfileLocker::CLI.start(ARGV)
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gemfile_locker/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'gemfile_locker'
8
+ spec.version = GemfileLocker::VERSION
9
+ spec.authors = ['Max Melentiev']
10
+ spec.email = ['melentievm@gmail.com']
11
+
12
+ spec.summary = <<-TXT
13
+ Tool to manage Gemfile. Lock and unlock all dependencies for safe `bundle update`.
14
+ TXT
15
+ spec.description = <<-TXT
16
+ GemfileLocker can lock all dependencies strictly or semi-strictly,
17
+ so it gets safe to run `bundle update` anytime.
18
+
19
+ It can unlock all dependencies so you can easily update to the latest versions.
20
+ TXT
21
+ spec.homepage = 'https://github.com/printercu/gemfile_locker'
22
+
23
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
24
+ f.match(%r{^(spec|features)/})
25
+ end
26
+ spec.bindir = 'exe'
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.add_runtime_dependency 'thor', '~> 0.19'
31
+ spec.add_runtime_dependency 'bundler', '~> 1.13'
32
+
33
+ spec.add_development_dependency 'rake', '~> 10.0'
34
+ end
@@ -0,0 +1,49 @@
1
+ require 'thor'
2
+
3
+ module GemfileLocker
4
+ class CLI < Thor
5
+ desc 'lock [Gemfile]', 'Lock dependencies.'
6
+ method_option :loose,
7
+ aliases: '-l',
8
+ lazy_default: 'patch',
9
+ enum: %w(major minor patch full),
10
+ desc: 'Lock with `~>`. Optionaly provide level (default to patch)'
11
+ method_option :only,
12
+ aliases: '-o',
13
+ type: :array,
14
+ desc: 'List of gems to process'
15
+ method_option :except,
16
+ aliases: '-e',
17
+ type: :array,
18
+ desc: 'List of gems to skip'
19
+ method_option :force,
20
+ aliases: '-f',
21
+ type: :boolean,
22
+ desc: 'Overwrite version definitions ' \
23
+ '(By default it adds only missing version definitions)'
24
+ def lock(file = 'Gemfile')
25
+ lockfile = File.read("#{file}.lock")
26
+ run_editor file, Locker.new(lockfile, options)
27
+ end
28
+
29
+ desc 'unlock [Gemfile]', 'Unlock dependencies.'
30
+ method_option :only,
31
+ aliases: '-o',
32
+ type: :array,
33
+ desc: 'List of gems to process'
34
+ method_option :except,
35
+ aliases: '-e',
36
+ type: :array,
37
+ desc: 'List of gems to skip'
38
+ def unlock(file = 'Gemfile')
39
+ run_editor file, Unlocker.new(options)
40
+ end
41
+
42
+ private
43
+
44
+ def run_editor(file, processor)
45
+ editor = FileEditor.new(file, processor)
46
+ editor.run
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,26 @@
1
+ module GemfileLocker
2
+ class FileEditor
3
+ attr_reader :path, :processor
4
+
5
+ def initialize(path, processor)
6
+ @path = path
7
+ @processor = processor
8
+ end
9
+
10
+ def run
11
+ write
12
+ end
13
+
14
+ def source
15
+ @source ||= File.read(path)
16
+ end
17
+
18
+ def result
19
+ @result ||= processor.call(source)
20
+ end
21
+
22
+ def write
23
+ File.write(path, result)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,76 @@
1
+ module GemfileLocker
2
+ class GemfileProcessor
3
+ GEM_LINE_REGEX = /
4
+ ^
5
+ (?<prefix>\s*gem\s*["'])
6
+ (?<name>[^'"]+)
7
+ (?<name_quote>['"])
8
+ (?<version_section>
9
+ (?<version_prefix>\s*,\s*['"])
10
+ (?<version>[^'"]*)
11
+ (?<version_quote>['"])
12
+ )?
13
+ (?<suffix>,?.*)?
14
+ $
15
+ /x
16
+ GEM_MATCH_FIELDS = %i(
17
+ prefix
18
+ name
19
+ name_quote
20
+ version_prefix
21
+ version
22
+ version_quote
23
+ suffix
24
+ ).freeze
25
+
26
+ attr_reader :path, :options
27
+
28
+ def initialize(options = {})
29
+ @options = options
30
+ end
31
+
32
+ def call(string)
33
+ process_gems(string) do |data|
34
+ process_gem(data) unless skip_gem?(data)
35
+ end
36
+ end
37
+
38
+ def skip_gem?(data)
39
+ if options[:only]
40
+ !options[:only].include?(data[:name])
41
+ elsif options[:except]
42
+ options[:except].include?(data[:name])
43
+ end
44
+ end
45
+
46
+ def process_gems(string)
47
+ string.gsub(GEM_LINE_REGEX) do
48
+ match = Regexp.last_match
49
+ data = GEM_MATCH_FIELDS.map { |x| [x, match[x]] }.to_h
50
+ result = yield data
51
+ result ||= data
52
+ GEM_MATCH_FIELDS.map { |x| result[x] }.join
53
+ end
54
+ end
55
+
56
+ def process_gem(_name, _data)
57
+ raise 'Abstract method'
58
+ end
59
+
60
+ def set_gem_version(data, version)
61
+ data = data.dup
62
+ if version
63
+ data[:version_prefix] ||= ", #{data[:name_quote] || "'"}"
64
+ data[:version_quote] ||= data[:name_quote] || "'"
65
+ data[:version] = version
66
+ else
67
+ %i(
68
+ version_prefix
69
+ version
70
+ version_quote
71
+ ).each { |x| data.delete(x) }
72
+ end
73
+ data
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,44 @@
1
+ require 'bundler'
2
+
3
+ module GemfileLocker
4
+ class Locker < GemfileProcessor
5
+ SEGMENTS_COUNT = {
6
+ major: 1,
7
+ minor: 2,
8
+ patch: 3,
9
+ full: 100,
10
+ }.freeze
11
+
12
+ attr_reader :lockfile
13
+
14
+ def initialize(lockfile, *args)
15
+ @lockfile = lockfile
16
+ super(*args)
17
+ end
18
+
19
+ def bundler_specs
20
+ @bundler_specs ||= Bundler::LockfileParser.new(lockfile).specs
21
+ end
22
+
23
+ def process_gem(data)
24
+ name = data[:name]
25
+ locked = bundler_specs.find { |x| x.name == name }
26
+ locked && set_gem_version(data, prepare_version(locked.version))
27
+ end
28
+
29
+ def skip_gem?(data)
30
+ super || data[:version] && !options[:force]
31
+ end
32
+
33
+ private
34
+
35
+ def prepare_version(version)
36
+ if options[:loose]
37
+ segments = version.segments.take(SEGMENTS_COUNT[options[:loose].to_sym])
38
+ "~> #{segments.join('.')}"
39
+ else
40
+ version.to_s
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,9 @@
1
+ module GemfileLocker
2
+ class Unlocker < GemfileProcessor
3
+ attr_reader :lockfile
4
+
5
+ def process_gem(data)
6
+ set_gem_version(data, nil)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ module GemfileLocker
2
+ VERSION = '0.1.0'.freeze
3
+
4
+ def self.gem_version
5
+ Gem::Version.new VERSION
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ require 'gemfile_locker/version'
2
+
3
+ module GemfileLocker
4
+ autoload :CLI, 'gemfile_locker/cli'
5
+ autoload :FileEditor, 'gemfile_locker/file_editor'
6
+ autoload :GemfileProcessor, 'gemfile_locker/gemfile_processor'
7
+ autoload :Locker, 'gemfile_locker/locker'
8
+ autoload :Unlocker, 'gemfile_locker/unlocker'
9
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gemfile_locker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Max Melentiev
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-11-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.19'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.19'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.13'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.13'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: |
56
+ GemfileLocker can lock all dependencies strictly or semi-strictly,
57
+ so it gets safe to run `bundle update` anytime.
58
+
59
+ It can unlock all dependencies so you can easily update to the latest versions.
60
+ email:
61
+ - melentievm@gmail.com
62
+ executables:
63
+ - gemfile_locker
64
+ extensions: []
65
+ extra_rdoc_files: []
66
+ files:
67
+ - ".gitignore"
68
+ - ".rspec"
69
+ - ".rubocop.yml"
70
+ - ".travis.yml"
71
+ - Gemfile
72
+ - LICENSE.txt
73
+ - README.md
74
+ - Rakefile
75
+ - bin/console
76
+ - bin/git-hooks/pre-commit
77
+ - bin/install_git_hooks
78
+ - bin/setup
79
+ - exe/gemfile_locker
80
+ - gemfile_locker.gemspec
81
+ - lib/gemfile_locker.rb
82
+ - lib/gemfile_locker/cli.rb
83
+ - lib/gemfile_locker/file_editor.rb
84
+ - lib/gemfile_locker/gemfile_processor.rb
85
+ - lib/gemfile_locker/locker.rb
86
+ - lib/gemfile_locker/unlocker.rb
87
+ - lib/gemfile_locker/version.rb
88
+ homepage: https://github.com/printercu/gemfile_locker
89
+ licenses: []
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.5.1
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Tool to manage Gemfile. Lock and unlock all dependencies for safe `bundle
111
+ update`.
112
+ test_files: []