gemnasium-parser 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
@@ -5,9 +5,9 @@ module Gemnasium
|
|
5
5
|
|
6
6
|
MATCHER = /(?:=|!=|>|<|>=|<=|~>)/
|
7
7
|
VERSION = /[0-9]+(?:\.[a-zA-Z0-9]+)*/
|
8
|
-
REQUIREMENT =
|
9
|
-
REQUIREMENT_LIST = /(?<qr1>["'])(?<req1>#{REQUIREMENT})\k<qr1>(
|
10
|
-
REQUIREMENTS = /(?:#{REQUIREMENT_LIST}|\[\
|
8
|
+
REQUIREMENT = /[ \t]*(?:#{MATCHER}[ \t]*)?#{VERSION}[ \t]*/
|
9
|
+
REQUIREMENT_LIST = /(?<qr1>["'])(?<req1>#{REQUIREMENT})\k<qr1>(?:[ \t]*,[ \t]*(?<qr2>["'])(?<req2>#{REQUIREMENT})\k<qr2>)?/
|
10
|
+
REQUIREMENTS = /(?:#{REQUIREMENT_LIST}|\[[ \t]*#{REQUIREMENT_LIST}[ \t]*\])/
|
11
11
|
|
12
12
|
KEY = /(?::\w+|:?"\w+"|:?'\w+')/
|
13
13
|
SYMBOL = /(?::\w+|:"[^"#]+"|:'[^']+')/
|
@@ -15,23 +15,24 @@ module Gemnasium
|
|
15
15
|
BOOLEAN = /(?:true|false)/
|
16
16
|
NIL = /nil/
|
17
17
|
ELEMENT = /(?:#{SYMBOL}|#{STRING})/
|
18
|
-
ARRAY = /\[(?:#{ELEMENT}(
|
18
|
+
ARRAY = /\[(?:#{ELEMENT}(?:[ \t]*,[ \t]*#{ELEMENT})*)?\]/
|
19
19
|
VALUE = /(?:#{BOOLEAN}|#{NIL}|#{ELEMENT}|#{ARRAY}|)/
|
20
|
-
PAIR = /(?:(#{KEY})\
|
21
|
-
OPTIONS = /#{PAIR}(
|
20
|
+
PAIR = /(?:(#{KEY})[ \t]*=>[ \t]*(#{VALUE})|(\w+):[ \t]+(#{VALUE}))/
|
21
|
+
OPTIONS = /#{PAIR}(?:[ \t]*,[ \t]*#{PAIR})*/
|
22
|
+
COMMENT = /(#[^\n]*)?/
|
22
23
|
|
23
|
-
GEM_CALL =
|
24
|
+
GEM_CALL = /^[ \t]*gem\(?[ \t]*(?<q1>["'])(?<name>#{GEM_NAME})\k<q1>(?:[ \t]*,[ \t]*#{REQUIREMENT_LIST})?(?:[ \t]*,[ \t]*(?<opts>#{OPTIONS}))?[ \t]*\)?[ \t]*#{COMMENT}$/
|
24
25
|
|
25
|
-
SYMBOLS = /#{SYMBOL}(\
|
26
|
-
GROUP_CALL = /^(?<i1
|
26
|
+
SYMBOLS = /#{SYMBOL}([ \t]*,[ \t]*#{SYMBOL})*/
|
27
|
+
GROUP_CALL = /^(?<i1>[ \t]*)group\(?[ \t]*(?<grps>#{SYMBOLS})[ \t]*\)?[ \t]+do[ \t]*?\n(?<blk>[^\n]*?)\n^\k<i1>end[ \t]*$/m
|
27
28
|
|
28
|
-
GIT_CALL = /^(?<i1
|
29
|
+
GIT_CALL = /^(?<i1>[ \t]*)git[ \(][^\n]*?do[ \t]*?\n(?<blk>.*?)\n^\k<i1>end[ \t]*$/m
|
29
30
|
|
30
|
-
PATH_CALL = /^(?<i1
|
31
|
+
PATH_CALL = /^(?<i1>[ \t]*)path[ \(][^\n]*?do[ \t]*?\n(?<blk>.*?)\n^\k<i1>end[ \t]*$/m
|
31
32
|
|
32
|
-
GEMSPEC_CALL =
|
33
|
+
GEMSPEC_CALL = /^[ \t]*gemspec(?:\(?[ \t]*(?<opts>#{OPTIONS}))?[ \t]*\)?[ \t]*$/
|
33
34
|
|
34
|
-
ADD_DEPENDENCY_CALL =
|
35
|
+
ADD_DEPENDENCY_CALL = /^[ \t]*\w+\.add(?<type>_runtime|_development)?_dependency\(?[ \t]*(?<q1>["'])(?<name>#{GEM_NAME})\k<q1>(?:[ \t]*,[ \t]*#{REQUIREMENTS})?[ \t]*\)?[ \t]*#{COMMENT}$/
|
35
36
|
|
36
37
|
def self.options(string)
|
37
38
|
{}.tap do |hash|
|
@@ -56,7 +57,7 @@ module Gemnasium
|
|
56
57
|
end
|
57
58
|
|
58
59
|
def self.values(string)
|
59
|
-
string.strip.split(
|
60
|
+
string.strip.split(/[ \t]*,[ \t]*/).map{|v| value(v) }
|
60
61
|
end
|
61
62
|
end
|
62
63
|
end
|
@@ -205,10 +205,11 @@ describe Gemnasium::Parser::Gemfile do
|
|
205
205
|
it "records dependency line numbers" do
|
206
206
|
content(<<-EOF)
|
207
207
|
gem "rake"
|
208
|
+
|
208
209
|
gem "rails"
|
209
210
|
EOF
|
210
211
|
dependencies[0].instance_variable_get(:@line).should == 1
|
211
|
-
dependencies[1].instance_variable_get(:@line).should ==
|
212
|
+
dependencies[1].instance_variable_get(:@line).should == 3
|
212
213
|
end
|
213
214
|
|
214
215
|
it "maps groups to types" do
|
@@ -241,4 +242,10 @@ describe Gemnasium::Parser::Gemfile do
|
|
241
242
|
dependency.name.should == "rake"
|
242
243
|
dependency.requirement.should == ">= 0.8.7"
|
243
244
|
end
|
245
|
+
|
246
|
+
it "parses gems followed by inline comments" do
|
247
|
+
content(%(gem "rake", ">= 0.8.7" # Comment))
|
248
|
+
dependency.name.should == "rake"
|
249
|
+
dependency.requirement.should == ">= 0.8.7"
|
250
|
+
end
|
244
251
|
end
|
@@ -119,11 +119,12 @@ describe Gemnasium::Parser::Gemspec do
|
|
119
119
|
content(<<-EOF)
|
120
120
|
Gem::Specification.new do |gem|
|
121
121
|
gem.add_dependency "rake"
|
122
|
+
|
122
123
|
gem.add_dependency "rails"
|
123
124
|
end
|
124
125
|
EOF
|
125
126
|
dependencies[0].instance_variable_get(:@line).should == 2
|
126
|
-
dependencies[1].instance_variable_get(:@line).should ==
|
127
|
+
dependencies[1].instance_variable_get(:@line).should == 4
|
127
128
|
end
|
128
129
|
|
129
130
|
it "parses parentheses" do
|
@@ -135,4 +136,14 @@ describe Gemnasium::Parser::Gemspec do
|
|
135
136
|
dependency.name.should == "rake"
|
136
137
|
dependency.requirement.should == ">= 0.8.7"
|
137
138
|
end
|
139
|
+
|
140
|
+
it "parses gems followed by inline comments" do
|
141
|
+
content(<<-EOF)
|
142
|
+
Gem::Specification.new do |gem|
|
143
|
+
gem.add_dependency "rake", ">= 0.8.7" # Comment
|
144
|
+
end
|
145
|
+
EOF
|
146
|
+
dependency.name.should == "rake"
|
147
|
+
dependency.requirement.should == ">= 0.8.7"
|
148
|
+
end
|
138
149
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gemnasium-parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-01-26 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &70152881719700 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.8.7
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70152881719700
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &70152881719200 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '2.7'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70152881719200
|
36
36
|
description: Safely parse Gemfiles and gemspecs
|
37
37
|
email: steve.richert@gmail.com
|
38
38
|
executables: []
|
@@ -76,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
76
|
version: '0'
|
77
77
|
requirements: []
|
78
78
|
rubyforge_project:
|
79
|
-
rubygems_version: 1.8.
|
79
|
+
rubygems_version: 1.8.15
|
80
80
|
signing_key:
|
81
81
|
specification_version: 3
|
82
82
|
summary: Safely parse Gemfiles and gemspecs
|