Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Parse gems that are followed by inline comments

  • Loading branch information...
commit b2b3c5a33250304f449e1127e7f0df1443709e46 1 parent d053c42
@remomueller remomueller authored laserlemon committed
View
5 lib/gemnasium/parser/patterns.rb
@@ -19,8 +19,9 @@ module Patterns
VALUE = /(?:#{BOOLEAN}|#{NIL}|#{ELEMENT}|#{ARRAY}|)/
PAIR = /(?:(#{KEY})\s*=>\s*(#{VALUE})|(\w+):\s+(#{VALUE}))/
OPTIONS = /#{PAIR}(?:\s*,\s*#{PAIR})*/
+ COMMENT = /(#.*)?/
- GEM_CALL = /^\s*gem\(?\s*(?<q1>["'])(?<name>#{GEM_NAME})\k<q1>(?:\s*,\s*#{REQUIREMENT_LIST})?(?:\s*,\s*(?<opts>#{OPTIONS}))?\s*\)?\s*$/
+ GEM_CALL = /^\s*gem\(?\s*(?<q1>["'])(?<name>#{GEM_NAME})\k<q1>(?:\s*,\s*#{REQUIREMENT_LIST})?(?:\s*,\s*(?<opts>#{OPTIONS}))?\s*\)?\s*#{COMMENT}$/
SYMBOLS = /#{SYMBOL}(\s*,\s*#{SYMBOL})*/
GROUP_CALL = /^(?<i1>\s*)group\(?\s*(?<grps>#{SYMBOLS})\s*\)?\s+do\s*?\n(?<blk>.*?)\n^\k<i1>end\s*$/m
@@ -31,7 +32,7 @@ module Patterns
GEMSPEC_CALL = /^\s*gemspec(?:\(?\s*(?<opts>#{OPTIONS}))?\s*\)?\s*$/
- ADD_DEPENDENCY_CALL = /^\s*\w+\.add(?<type>_runtime|_development)?_dependency\(?\s*(?<q1>["'])(?<name>#{GEM_NAME})\k<q1>(?:\s*,\s*#{REQUIREMENTS})?\s*\)?\s*$/
+ ADD_DEPENDENCY_CALL = /^\s*\w+\.add(?<type>_runtime|_development)?_dependency\(?\s*(?<q1>["'])(?<name>#{GEM_NAME})\k<q1>(?:\s*,\s*#{REQUIREMENTS})?\s*\)?\s*#{COMMENT}$/
def self.options(string)
{}.tap do |hash|
View
6 spec/gemnasium/parser/gemfile_spec.rb
@@ -241,4 +241,10 @@ def reset
dependency.name.should == "rake"
dependency.requirement.should == ">= 0.8.7"
end
+
+ it "parses gems followed by inline comments" do
+ content(%(gem "rake", ">= 0.8.7" # Comment))
+ dependency.name.should == "rake"
+ dependency.requirement.should == ">= 0.8.7"
+ end
end
View
10 spec/gemnasium/parser/gemspec_spec.rb
@@ -135,4 +135,14 @@ def reset
dependency.name.should == "rake"
dependency.requirement.should == ">= 0.8.7"
end
+
+ it "parses gems followed by inline comments" do
+ content(<<-EOF)
+ Gem::Specification.new do |gem|
+ gem.add_dependency "rake", ">= 0.8.7" # Comment
+ end
+ EOF
+ dependency.name.should == "rake"
+ dependency.requirement.should == ">= 0.8.7"
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.