gemnasium-parser 0.1.2 → 0.1.3

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.
@@ -5,9 +5,9 @@ module Gemnasium
5
5
 
6
6
  MATCHER = /(?:=|!=|>|<|>=|<=|~>)/
7
7
  VERSION = /[0-9]+(?:\.[a-zA-Z0-9]+)*/
8
- REQUIREMENT = /\s*(?:#{MATCHER}\s*)?#{VERSION}\s*/
9
- REQUIREMENT_LIST = /(?<qr1>["'])(?<req1>#{REQUIREMENT})\k<qr1>(?:\s*,\s*(?<qr2>["'])(?<req2>#{REQUIREMENT})\k<qr2>)?/
10
- REQUIREMENTS = /(?:#{REQUIREMENT_LIST}|\[\s*#{REQUIREMENT_LIST}\s*\])/
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}(?:\s*,\s*#{ELEMENT})*)?\]/
18
+ ARRAY = /\[(?:#{ELEMENT}(?:[ \t]*,[ \t]*#{ELEMENT})*)?\]/
19
19
  VALUE = /(?:#{BOOLEAN}|#{NIL}|#{ELEMENT}|#{ARRAY}|)/
20
- PAIR = /(?:(#{KEY})\s*=>\s*(#{VALUE})|(\w+):\s+(#{VALUE}))/
21
- OPTIONS = /#{PAIR}(?:\s*,\s*#{PAIR})*/
20
+ PAIR = /(?:(#{KEY})[ \t]*=>[ \t]*(#{VALUE})|(\w+):[ \t]+(#{VALUE}))/
21
+ OPTIONS = /#{PAIR}(?:[ \t]*,[ \t]*#{PAIR})*/
22
+ COMMENT = /(#[^\n]*)?/
22
23
 
23
- GEM_CALL = /^\s*gem\(?\s*(?<q1>["'])(?<name>#{GEM_NAME})\k<q1>(?:\s*,\s*#{REQUIREMENT_LIST})?(?:\s*,\s*(?<opts>#{OPTIONS}))?\s*\)?\s*$/
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}(\s*,\s*#{SYMBOL})*/
26
- GROUP_CALL = /^(?<i1>\s*)group\(?\s*(?<grps>#{SYMBOLS})\s*\)?\s+do\s*?\n(?<blk>.*?)\n^\k<i1>end\s*$/m
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>\s*)git[\s\(].*?do\s*?\n(?<blk>.*?)\n^\k<i1>end\s*$/m
29
+ GIT_CALL = /^(?<i1>[ \t]*)git[ \(][^\n]*?do[ \t]*?\n(?<blk>.*?)\n^\k<i1>end[ \t]*$/m
29
30
 
30
- PATH_CALL = /^(?<i1>\s*)path[\s\(].*?do\s*?\n(?<blk>.*?)\n^\k<i1>end\s*$/m
31
+ PATH_CALL = /^(?<i1>[ \t]*)path[ \(][^\n]*?do[ \t]*?\n(?<blk>.*?)\n^\k<i1>end[ \t]*$/m
31
32
 
32
- GEMSPEC_CALL = /^\s*gemspec(?:\(?\s*(?<opts>#{OPTIONS}))?\s*\)?\s*$/
33
+ GEMSPEC_CALL = /^[ \t]*gemspec(?:\(?[ \t]*(?<opts>#{OPTIONS}))?[ \t]*\)?[ \t]*$/
33
34
 
34
- ADD_DEPENDENCY_CALL = /^\s*\w+\.add(?<type>_runtime|_development)?_dependency\(?\s*(?<q1>["'])(?<name>#{GEM_NAME})\k<q1>(?:\s*,\s*#{REQUIREMENTS})?\s*\)?\s*$/
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(/\s*,\s*/).map{|v| value(v) }
60
+ string.strip.split(/[ \t]*,[ \t]*/).map{|v| value(v) }
60
61
  end
61
62
  end
62
63
  end
@@ -1,5 +1,5 @@
1
1
  module Gemnasium
2
2
  module Parser
3
- VERSION = "0.1.2"
3
+ VERSION = "0.1.3"
4
4
  end
5
5
  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 == 2
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 == 3
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.2
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: 2011-12-16 00:00:00.000000000Z
12
+ date: 2012-01-26 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &70197965178760 !ruby/object:Gem::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: *70197965178760
24
+ version_requirements: *70152881719700
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70197965178260 !ruby/object:Gem::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: *70197965178260
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.12
79
+ rubygems_version: 1.8.15
80
80
  signing_key:
81
81
  specification_version: 3
82
82
  summary: Safely parse Gemfiles and gemspecs