pessimize 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +11 -0
- data/.rubocop.yml +1171 -0
- data/CHANGELOG +11 -0
- data/Gemfile +0 -1
- data/README.md +3 -3
- data/lib/pessimize/gem.rb +1 -1
- data/lib/pessimize/gemfile.rb +39 -18
- data/lib/pessimize/version.rb +1 -1
- data/pessimize.gemspec +1 -0
- data/spec/gem_spec.rb +24 -0
- data/spec/gemfile_spec.rb +68 -0
- data/spec/integration_spec.rb +49 -0
- data/spec/spec_helper.rb +2 -0
- metadata +50 -33
data/CHANGELOG
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
=== Pessimize 0.3.0
|
2
|
+
|
3
|
+
Features:
|
4
|
+
* Increased compatibility with Gemfile syntax, which should support
|
5
|
+
practically all Gemfiles.
|
6
|
+
* Some minor refactoring for clarity (ongoing, as always)
|
7
|
+
|
8
|
+
Bug fixes:
|
9
|
+
* Fix issue with certain valid ruby expressions not being parsed correctly,
|
10
|
+
e.g. new lines in "gem" definitions
|
11
|
+
|
1
12
|
=== Pessimize 0.2.0
|
2
13
|
|
3
14
|
Features:
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/pessimize.png)](http://badge.fury.io/rb/pessimize)
|
4
4
|
[![Build Status](https://travis-ci.org/joonty/pessimize.png?branch=master)](https://travis-ci.org/joonty/pessimize)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/joonty/pessimize/badges/gpa.svg)](https://codeclimate.com/github/joonty/pessimize)
|
6
|
+
[![Test Coverage](https://codeclimate.com/github/joonty/pessimize/badges/coverage.svg)](https://codeclimate.com/github/joonty/pessimize/coverage)
|
5
7
|
|
6
8
|
### Who is this for?
|
7
9
|
Anyone who works with a Gemfile, i.e. a project that uses [bundler][1].
|
@@ -65,9 +67,7 @@ Also, by default, the Gemfile and Gemfile.lock are copied as a form of backup. T
|
|
65
67
|
|
66
68
|
## Known issues
|
67
69
|
|
68
|
-
|
69
|
-
|
70
|
-
[See this issue][3] for tracking the progress.
|
70
|
+
Recent issues with certain Gemfile syntax edge cases have been fixed, so there are currently no known issues. If you do find pessimize doing something strange, or not correctly picking up information in your Gemfile, it would be greatly appreciated if you submit an issue.
|
71
71
|
|
72
72
|
## Why `bundle update` can be dangerous
|
73
73
|
|
data/lib/pessimize/gem.rb
CHANGED
@@ -49,7 +49,7 @@ module Pessimize
|
|
49
49
|
token_before_version = original_tokens.index { |t| t[1] == :on_comma }
|
50
50
|
if token_before_version
|
51
51
|
remaining_tokens = original_tokens[(token_before_version + 1)..-1]
|
52
|
-
while [:on_sp, :on_tstring_beg].include? remaining_tokens.first[1]
|
52
|
+
while [:on_sp, :on_tstring_beg, :on_ignored_nl].include? remaining_tokens.first[1]
|
53
53
|
remaining_tokens.shift
|
54
54
|
token_before_version += 1
|
55
55
|
end
|
data/lib/pessimize/gemfile.rb
CHANGED
@@ -3,33 +3,25 @@ require 'pessimize/gem'
|
|
3
3
|
|
4
4
|
module Pessimize
|
5
5
|
class Gemfile
|
6
|
-
attr_reader :
|
6
|
+
attr_reader :gems
|
7
7
|
|
8
8
|
def initialize(contents)
|
9
|
-
self.tokens
|
10
|
-
self.gems
|
9
|
+
self.tokens = Ripper.lex(contents)
|
10
|
+
self.gems = []
|
11
11
|
self.gem_token_map = []
|
12
|
-
|
12
|
+
|
13
|
+
parse_gems_from_tokens!
|
13
14
|
end
|
14
15
|
|
15
16
|
def to_s
|
16
|
-
|
17
|
-
current_offset = 0
|
18
|
-
gem_token_map.zip(gems).each do |(tok_start, tok_end), gem|
|
19
|
-
gem_tokens = gem.tokens
|
20
|
-
compiled_tokens[(current_offset + tok_start)..(current_offset + tok_end)] = gem_tokens
|
21
|
-
current_offset += gem_tokens.length - (tok_end - tok_start + 1)
|
22
|
-
end
|
23
|
-
compiled_tokens.inject("") { |a, e|
|
24
|
-
a + e[2]
|
25
|
-
}
|
17
|
+
TokenCompiler.new(tokens).compile_to_string(gems, gem_token_map)
|
26
18
|
end
|
27
19
|
|
28
20
|
protected
|
29
|
-
attr_writer :gems
|
30
|
-
attr_accessor :gem_token_map
|
21
|
+
attr_writer :gems
|
22
|
+
attr_accessor :gem_token_map, :tokens
|
31
23
|
|
32
|
-
def
|
24
|
+
def parse_gems_from_tokens!
|
33
25
|
enum = tokens.each_with_index
|
34
26
|
|
35
27
|
loop do
|
@@ -37,7 +29,7 @@ module Pessimize
|
|
37
29
|
|
38
30
|
if tok[1] == :on_ident && tok[2] == "gem"
|
39
31
|
gem_toks = []
|
40
|
-
until [
|
32
|
+
until all_gem_tokens_collected?(tok[0], enum.peek[0])
|
41
33
|
(tok, j) = enum.next
|
42
34
|
gem_toks << tok
|
43
35
|
end
|
@@ -48,5 +40,34 @@ module Pessimize
|
|
48
40
|
end
|
49
41
|
rescue StopIteration
|
50
42
|
end
|
43
|
+
|
44
|
+
def all_gem_tokens_collected?(current_token, next_token)
|
45
|
+
next_token[1] == :on_nl
|
46
|
+
end
|
47
|
+
|
48
|
+
class TokenCompiler
|
49
|
+
def initialize(tokens)
|
50
|
+
self.tokens = tokens.dup
|
51
|
+
self.offset = 0
|
52
|
+
end
|
53
|
+
|
54
|
+
def compile_to_string(gems, gem_token_map)
|
55
|
+
gem_token_map.zip(gems).each do |(token_start, token_end), gem|
|
56
|
+
insert_gem_into_tokens! gem, token_start, token_end
|
57
|
+
end
|
58
|
+
|
59
|
+
tokens.reduce("") { |a, e|
|
60
|
+
a + e[2]
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
protected
|
65
|
+
attr_accessor :tokens, :offset
|
66
|
+
|
67
|
+
def insert_gem_into_tokens!(gem, token_start, token_end)
|
68
|
+
self.tokens[(offset + token_start)..(offset + token_end)] = gem.tokens
|
69
|
+
self.offset += gem.tokens.length - (token_end - token_start + 1)
|
70
|
+
end
|
71
|
+
end
|
51
72
|
end
|
52
73
|
end
|
data/lib/pessimize/version.rb
CHANGED
data/pessimize.gemspec
CHANGED
@@ -18,6 +18,7 @@ This is for people who work with projects that use bundler, such as rails projec
|
|
18
18
|
gem.add_dependency 'trollop'
|
19
19
|
gem.add_development_dependency 'rspec', '~> 2.13.0'
|
20
20
|
gem.add_development_dependency 'rake', '~> 10.0.3'
|
21
|
+
gem.add_development_dependency "codeclimate-test-reporter"
|
21
22
|
|
22
23
|
gem.files = `git ls-files`.split($/)
|
23
24
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
data/spec/gem_spec.rb
CHANGED
@@ -70,5 +70,29 @@ module Pessimize
|
|
70
70
|
end
|
71
71
|
|
72
72
|
end
|
73
|
+
|
74
|
+
context "creating a gem using new lines for arguments" do
|
75
|
+
let(:gem_string) { <<GEM.strip
|
76
|
+
gem "blah",
|
77
|
+
"2.0.0beta",
|
78
|
+
group: :development
|
79
|
+
GEM
|
80
|
+
}
|
81
|
+
|
82
|
+
let(:gem) { Gem.new(Ripper.lex(gem_string)) }
|
83
|
+
subject { gem }
|
84
|
+
|
85
|
+
its(:name) { should == "blah" }
|
86
|
+
its(:version) { should == "2.0.0beta" }
|
87
|
+
|
88
|
+
context "after setting the version" do
|
89
|
+
before do
|
90
|
+
gem.version = "~> 2.1"
|
91
|
+
end
|
92
|
+
|
93
|
+
its(:to_s) { should == %Q(gem "blah",\n "~> 2.1",\n group: :development) }
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
73
97
|
end
|
74
98
|
end
|
data/spec/gemfile_spec.rb
CHANGED
@@ -118,5 +118,73 @@ GEM
|
|
118
118
|
its(:to_s) { should == expected_defn }
|
119
119
|
end
|
120
120
|
end
|
121
|
+
|
122
|
+
context "with multiple gem definitions spanning multiple lines" do
|
123
|
+
|
124
|
+
let(:gem_defn) { <<-GEM
|
125
|
+
source "https://rubygems.org"
|
126
|
+
|
127
|
+
gem "monkey",
|
128
|
+
"2.0.0"
|
129
|
+
|
130
|
+
gem "thor",
|
131
|
+
">= 1.3.0"
|
132
|
+
GEM
|
133
|
+
}
|
134
|
+
|
135
|
+
subject(:gemfile) { Gemfile.new(gem_defn) }
|
136
|
+
|
137
|
+
its(:to_s) { should == gem_defn }
|
138
|
+
|
139
|
+
describe "#gems" do
|
140
|
+
subject(:gems) { gemfile.gems }
|
141
|
+
|
142
|
+
its(:length) { should == 2 }
|
143
|
+
|
144
|
+
describe "the first gem" do
|
145
|
+
subject(:gem) { gems[0] }
|
146
|
+
|
147
|
+
its(:name) { should == "monkey" }
|
148
|
+
its(:version) { should == "2.0.0" }
|
149
|
+
its(:to_s) { should == %Q( "monkey",\n "2.0.0") }
|
150
|
+
|
151
|
+
context "setting the version" do
|
152
|
+
before do
|
153
|
+
gem.version = "~> 2.0.0"
|
154
|
+
end
|
155
|
+
|
156
|
+
its(:to_s) { should == %Q( "monkey",\n "~> 2.0.0") }
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe "the second gem" do
|
161
|
+
subject { gems[1] }
|
162
|
+
|
163
|
+
its(:name) { should == "thor" }
|
164
|
+
its(:version) { should == ">= 1.3.0" }
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
context "after setting the gem versions" do
|
169
|
+
before do
|
170
|
+
gemfile.gems.each do |gem|
|
171
|
+
gem.version = "~> 1.0.0"
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
let(:expected_defn) { <<-GEM
|
176
|
+
source "https://rubygems.org"
|
177
|
+
|
178
|
+
gem "monkey",
|
179
|
+
"~> 1.0.0"
|
180
|
+
|
181
|
+
gem "thor",
|
182
|
+
"~> 1.0.0"
|
183
|
+
GEM
|
184
|
+
}
|
185
|
+
|
186
|
+
its(:to_s) { should == expected_defn }
|
187
|
+
end
|
188
|
+
end
|
121
189
|
end
|
122
190
|
end
|
data/spec/integration_spec.rb
CHANGED
@@ -538,4 +538,53 @@ end
|
|
538
538
|
|
539
539
|
it_behaves_like "a working pessimizer without backups", gemfile, lockfile, result, '--no-backup'
|
540
540
|
end
|
541
|
+
|
542
|
+
context "with a Gemfile using new lines for gem definitions" do
|
543
|
+
gemfile = <<-EOD
|
544
|
+
source "https://rubygems.org"
|
545
|
+
gem 'json',
|
546
|
+
group: :production
|
547
|
+
|
548
|
+
gem 'pessimize',
|
549
|
+
github: "joonty/pessimize"
|
550
|
+
|
551
|
+
group :development, :test do
|
552
|
+
gem 'sqlite3',
|
553
|
+
'>= 1.3.7'
|
554
|
+
end
|
555
|
+
EOD
|
556
|
+
|
557
|
+
lockfile = <<-EOD
|
558
|
+
GIT
|
559
|
+
remote: git://github.com/joonty/pessimize.git
|
560
|
+
revision: 40f6ec6c7483a453b72e09efbba0e0d7de3b37ab
|
561
|
+
specs:
|
562
|
+
pessimize (0.2.0)
|
563
|
+
bundler
|
564
|
+
trollop
|
565
|
+
|
566
|
+
GEM
|
567
|
+
remote: https://rubygems.org/
|
568
|
+
specs:
|
569
|
+
json (1.8.0)
|
570
|
+
trollop (2.1.2)
|
571
|
+
sqlite3 (1.3.7)
|
572
|
+
EOD
|
573
|
+
|
574
|
+
result = <<-EOD
|
575
|
+
source "https://rubygems.org"
|
576
|
+
gem 'json', "~> 1.8",
|
577
|
+
group: :production
|
578
|
+
|
579
|
+
gem 'pessimize',
|
580
|
+
github: "joonty/pessimize"
|
581
|
+
|
582
|
+
group :development, :test do
|
583
|
+
gem 'sqlite3',
|
584
|
+
'~> 1.3'
|
585
|
+
end
|
586
|
+
EOD
|
587
|
+
|
588
|
+
it_behaves_like "a working pessimizer", gemfile, lockfile, result
|
589
|
+
end
|
541
590
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,71 +1,85 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pessimize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Cairns
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
15
22
|
version_requirements: !ruby/object:Gem::Requirement
|
16
23
|
requirements:
|
17
|
-
- -
|
24
|
+
- - ">="
|
18
25
|
- !ruby/object:Gem::Version
|
19
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: trollop
|
20
29
|
requirement: !ruby/object:Gem::Requirement
|
21
30
|
requirements:
|
22
|
-
- -
|
31
|
+
- - ">="
|
23
32
|
- !ruby/object:Gem::Version
|
24
33
|
version: '0'
|
25
|
-
prerelease: false
|
26
34
|
type: :runtime
|
27
|
-
|
28
|
-
name: trollop
|
35
|
+
prerelease: false
|
29
36
|
version_requirements: !ruby/object:Gem::Requirement
|
30
37
|
requirements:
|
31
|
-
- -
|
38
|
+
- - ">="
|
32
39
|
- !ruby/object:Gem::Version
|
33
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
34
43
|
requirement: !ruby/object:Gem::Requirement
|
35
44
|
requirements:
|
36
|
-
- -
|
45
|
+
- - "~>"
|
37
46
|
- !ruby/object:Gem::Version
|
38
|
-
version:
|
47
|
+
version: 2.13.0
|
48
|
+
type: :development
|
39
49
|
prerelease: false
|
40
|
-
type: :runtime
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rspec
|
43
50
|
version_requirements: !ruby/object:Gem::Requirement
|
44
51
|
requirements:
|
45
|
-
- - ~>
|
52
|
+
- - "~>"
|
46
53
|
- !ruby/object:Gem::Version
|
47
54
|
version: 2.13.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
48
57
|
requirement: !ruby/object:Gem::Requirement
|
49
58
|
requirements:
|
50
|
-
- - ~>
|
59
|
+
- - "~>"
|
51
60
|
- !ruby/object:Gem::Version
|
52
|
-
version:
|
53
|
-
prerelease: false
|
61
|
+
version: 10.0.3
|
54
62
|
type: :development
|
55
|
-
|
56
|
-
name: rake
|
63
|
+
prerelease: false
|
57
64
|
version_requirements: !ruby/object:Gem::Requirement
|
58
65
|
requirements:
|
59
|
-
- - ~>
|
66
|
+
- - "~>"
|
60
67
|
- !ruby/object:Gem::Version
|
61
68
|
version: 10.0.3
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: codeclimate-test-reporter
|
62
71
|
requirement: !ruby/object:Gem::Requirement
|
63
72
|
requirements:
|
64
|
-
- -
|
73
|
+
- - ">="
|
65
74
|
- !ruby/object:Gem::Version
|
66
|
-
version:
|
67
|
-
prerelease: false
|
75
|
+
version: '0'
|
68
76
|
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
description: |-
|
70
84
|
Add the pessimistic constraint operator to all gems in your Gemfile, restricting the maximum update version.
|
71
85
|
|
@@ -77,8 +91,10 @@ executables:
|
|
77
91
|
extensions: []
|
78
92
|
extra_rdoc_files: []
|
79
93
|
files:
|
80
|
-
- .
|
81
|
-
- .
|
94
|
+
- ".codeclimate.yml"
|
95
|
+
- ".gitignore"
|
96
|
+
- ".rubocop.yml"
|
97
|
+
- ".travis.yml"
|
82
98
|
- CHANGELOG
|
83
99
|
- Gemfile
|
84
100
|
- LICENSE.txt
|
@@ -107,26 +123,27 @@ homepage: https://github.com/joonty/pessimize
|
|
107
123
|
licenses:
|
108
124
|
- MIT
|
109
125
|
metadata: {}
|
110
|
-
post_install_message:
|
126
|
+
post_install_message:
|
111
127
|
rdoc_options: []
|
112
128
|
require_paths:
|
113
129
|
- lib
|
114
130
|
required_ruby_version: !ruby/object:Gem::Requirement
|
115
131
|
requirements:
|
116
|
-
- -
|
132
|
+
- - ">="
|
117
133
|
- !ruby/object:Gem::Version
|
118
134
|
version: '0'
|
119
135
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
136
|
requirements:
|
121
|
-
- -
|
137
|
+
- - ">="
|
122
138
|
- !ruby/object:Gem::Version
|
123
139
|
version: '0'
|
124
140
|
requirements: []
|
125
|
-
rubyforge_project:
|
126
|
-
rubygems_version: 2.
|
127
|
-
signing_key:
|
141
|
+
rubyforge_project:
|
142
|
+
rubygems_version: 2.2.2
|
143
|
+
signing_key:
|
128
144
|
specification_version: 4
|
129
|
-
summary: Add the pessimistic constraint operator to all gems in your Gemfile, restricting
|
145
|
+
summary: Add the pessimistic constraint operator to all gems in your Gemfile, restricting
|
146
|
+
the maximum update version.
|
130
147
|
test_files:
|
131
148
|
- spec/data/Gemfile.lock.example
|
132
149
|
- spec/data/Gemfile.lock.example2
|