gemnasium-parser 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,7 +18,7 @@ module Gemnasium
18
18
 
19
19
  private
20
20
  def runtime_matches
21
- @runtime_matches ||= matches(Patterns::RUNTIME_CALL)
21
+ @runtime_matches ||= matches(Patterns::ADD_DEPENDENCY_CALL)
22
22
  end
23
23
 
24
24
  def matches(pattern)
@@ -20,18 +20,18 @@ module Gemnasium
20
20
  PAIR = /(?:(#{KEY})\s*=>\s*(#{VALUE})|(\w+):\s+(#{VALUE}))/
21
21
  OPTIONS = /#{PAIR}(?:\s*,\s*#{PAIR})*/
22
22
 
23
- GEM_CALL = /^\s*gem\s+(?<q1>["'])(?<name>#{GEM_NAME})\k<q1>(?:\s*,\s*#{REQUIREMENT_LIST})?(?:\s*,\s*(?<opts>#{OPTIONS}))?\s*$/
23
+ GEM_CALL = /^\s*gem\s*\(?\s*(?<q1>["'])(?<name>#{GEM_NAME})\k<q1>(?:\s*,\s*#{REQUIREMENT_LIST})?(?:\s*,\s*(?<opts>#{OPTIONS}))?\s*\)?\s*$/
24
24
 
25
25
  SYMBOLS = /#{SYMBOL}(\s*,\s*#{SYMBOL})*/
26
- GROUP_CALL = /^(?<i1>\s*)group\s+(?<grps>#{SYMBOLS})\s+do\s*?\n(?<blk>.*?)\n^\k<i1>end\s*$/m
26
+ GROUP_CALL = /^(?<i1>\s*)group\s*\(?\s*(?<grps>#{SYMBOLS})\s*\)?\s+do\s*?\n(?<blk>.*?)\n^\k<i1>end\s*$/m
27
27
 
28
- GIT_CALL = /^(?<i1>\s*)git\s+.*?\n(?<blk>.*?)\n^\k<i1>end\s*$/m
28
+ GIT_CALL = /^(?<i1>\s*)git[\s\(].*?do\s*?\n(?<blk>.*?)\n^\k<i1>end\s*$/m
29
29
 
30
- PATH_CALL = /^(?<i1>\s*)path\s+.*?\n(?<blk>.*?)\n^\k<i1>end\s*$/m
30
+ PATH_CALL = /^(?<i1>\s*)path[\s\(].*?do\s*?\n(?<blk>.*?)\n^\k<i1>end\s*$/m
31
31
 
32
32
  GEMSPEC_CALL = /^\s*gemspec(?:\s+(?<opts>#{OPTIONS}))?\s*$/
33
33
 
34
- RUNTIME_CALL = /^\s*\w+\.add(?<type>_runtime|_development)?_dependency\s+(?<q1>["'])(?<name>#{GEM_NAME})\k<q1>(?:\s*,\s*#{REQUIREMENTS})?\s*$/
34
+ ADD_DEPENDENCY_CALL = /^\s*\w+\.add(?<type>_runtime|_development)?_dependency\s*\(?\s*(?<q1>["'])(?<name>#{GEM_NAME})\k<q1>(?:\s*,\s*#{REQUIREMENTS})?\s*\)?\s*$/
35
35
 
36
36
  def self.options(string)
37
37
  {}.tap do |hash|
@@ -1,5 +1,5 @@
1
1
  module Gemnasium
2
2
  module Parser
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -122,6 +122,15 @@ describe Gemnasium::Parser::Gemfile do
122
122
  dependencies[2].groups.should == [:development]
123
123
  end
124
124
 
125
+ it "parses gems in a group with parentheses" do
126
+ content(<<-EOF)
127
+ group(:production) do
128
+ gem "pg"
129
+ end
130
+ EOF
131
+ dependency.groups.should == [:production]
132
+ end
133
+
125
134
  it "parses gems in multiple groups" do
126
135
  content(<<-EOF)
127
136
  group :development, :test do
@@ -161,6 +170,15 @@ describe Gemnasium::Parser::Gemfile do
161
170
  dependencies.size.should == 0
162
171
  end
163
172
 
173
+ it "ignores gems in a git block with parentheses" do
174
+ content(<<-EOF)
175
+ git("https://github.com/rails/rails.git") do
176
+ gem "rails"
177
+ end
178
+ EOF
179
+ dependencies.size.should == 0
180
+ end
181
+
164
182
  it "ignores gems in a path block" do
165
183
  content(<<-EOF)
166
184
  path "vendor/rails" do
@@ -170,6 +188,15 @@ describe Gemnasium::Parser::Gemfile do
170
188
  dependencies.size.should == 0
171
189
  end
172
190
 
191
+ it "ignores gems in a path block with parentheses" do
192
+ content(<<-EOF)
193
+ path("vendor/rails") do
194
+ gem "rails"
195
+ end
196
+ EOF
197
+ dependencies.size.should == 0
198
+ end
199
+
173
200
  it "records dependency line numbers" do
174
201
  content(<<-EOF)
175
202
  gem "rake"
@@ -203,4 +230,10 @@ describe Gemnasium::Parser::Gemfile do
203
230
  dependencies[2].type.should == :runtime
204
231
  dependencies[3].type.should == :development
205
232
  end
233
+
234
+ it "parses parentheses" do
235
+ content(%(gem("rake", ">= 0.8.7")))
236
+ dependency.name.should == "rake"
237
+ dependency.requirement.should == ">= 0.8.7"
238
+ end
206
239
  end
@@ -125,4 +125,14 @@ describe Gemnasium::Parser::Gemspec do
125
125
  dependencies[0].instance_variable_get(:@line).should == 2
126
126
  dependencies[1].instance_variable_get(:@line).should == 3
127
127
  end
128
+
129
+ it "parses parentheses" do
130
+ content(<<-EOF)
131
+ Gem::Specification.new do |gem|
132
+ gem.add_dependency("rake", ">= 0.8.7")
133
+ end
134
+ EOF
135
+ dependency.name.should == "rake"
136
+ dependency.requirement.should == ">= 0.8.7"
137
+ end
128
138
  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.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-12-15 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &70223212269420 !ruby/object:Gem::Requirement
16
+ requirement: &70182727808960 !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: *70223212269420
24
+ version_requirements: *70182727808960
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70223212268920 !ruby/object:Gem::Requirement
27
+ requirement: &70182727808460 !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: *70223212268920
35
+ version_requirements: *70182727808460
36
36
  description: Safely parse Gemfiles and gemspecs
37
37
  email: steve.richert@gmail.com
38
38
  executables: []