From 8f7df005f5af5a78dd349e9baa86e8b2786f118e Mon Sep 17 00:00:00 2001 From: Ketan Padegaonkar Date: Sat, 9 Nov 2013 12:52:26 +0530 Subject: [PATCH 1/2] Add the ability to parse the ruby version specification in the gem file --- lib/gemnasium/parser/gemfile.rb | 9 +++++++++ lib/gemnasium/parser/patterns.rb | 3 +++ spec/gemnasium/parser/gemfile_spec.rb | 15 +++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/lib/gemnasium/parser/gemfile.rb b/lib/gemnasium/parser/gemfile.rb index 81b1a78..106c623 100644 --- a/lib/gemnasium/parser/gemfile.rb +++ b/lib/gemnasium/parser/gemfile.rb @@ -28,6 +28,15 @@ def gemspec end end + def ruby + @ruby ||= begin + if spec = matches(Patterns::RUBY_CALL).last + opts = Patterns.options(spec["opts"]) + Bundler::RubyVersion.new(spec['version'], opts['engine'], opts['engine_version']) + end + end + end + def gemspec? !!gemspec end diff --git a/lib/gemnasium/parser/patterns.rb b/lib/gemnasium/parser/patterns.rb index a98ffc9..ba4067f 100644 --- a/lib/gemnasium/parser/patterns.rb +++ b/lib/gemnasium/parser/patterns.rb @@ -35,6 +35,9 @@ module Patterns ADD_DEPENDENCY_CALL = /^[ \t]*\w+\.add(?_runtime|_development)?_dependency\(?[ \t]*#{QUOTED_GEM_NAME}(?:[ \t]*,[ \t]*#{REQUIREMENTS})?[ \t]*\)?[ \t]*#{COMMENT}$/ + QUOTED_RUBY_VERSION = /(?:(?["'])(?#{VERSION})\k|%q<(?#{VERSION})>)/ + RUBY_CALL = /^[ \t]*ruby\(?[ \t]*#{QUOTED_RUBY_VERSION}(?:[ \t]*,[ \t]*(?#{OPTIONS}))?[ \t]*\)?[ \t]*#{COMMENT}$/ + def self.options(string) {}.tap do |hash| return hash unless string diff --git a/spec/gemnasium/parser/gemfile_spec.rb b/spec/gemnasium/parser/gemfile_spec.rb index 9ae6ba6..1de9f95 100644 --- a/spec/gemnasium/parser/gemfile_spec.rb +++ b/spec/gemnasium/parser/gemfile_spec.rb @@ -43,6 +43,21 @@ def reset dependencies.size.should == 0 end + it "does not barf on missing ruby specification" do + content(%(gem "rake")) + gemfile.ruby.should == nil + end + + it "detects ruby specification" do + content(%(ruby "1.8.7")) + gemfile.ruby.should == Bundler::RubyVersion.new('1.8.7', 'ruby', '1.8.7') + end + + it "detects ruby specification with engine and engine_version" do + content(%(ruby "1.8.7", :engine => "jruby", :engine_version => "1.6.7")) + gemfile.ruby.should == Bundler::RubyVersion.new('1.8.7', 'jruby', '1.6.7') + end + it "parses gems with a period in the name" do content(%(gem "pygment.rb", ">= 0.8.7")) dependency.name.should == "pygment.rb" From 504c078591f5c7554a2261f5d6f19e12f2bc3351 Mon Sep 17 00:00:00 2001 From: Ketan Padegaonkar Date: Sat, 9 Nov 2013 12:54:04 +0530 Subject: [PATCH 2/2] Bump version --- CHANGELOG.md | 6 +++++- gemnasium-parser.gemspec | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 110d145..90064d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.2.0 / 2013-11-09 + +* add the ability to parse the ruby version specification + ## 0.1.9 / 2012-11-19 Bugfixes: @@ -10,7 +14,7 @@ Bugfixes: * support :github option and exclude gems that use it * add CHANGELOG - + ## 0.1.7 2012-10-17 Bugfixes: diff --git a/gemnasium-parser.gemspec b/gemnasium-parser.gemspec index b4aa1ff..e22170d 100644 --- a/gemnasium-parser.gemspec +++ b/gemnasium-parser.gemspec @@ -2,7 +2,7 @@ Gem::Specification.new do |gem| gem.name = "gemnasium-parser" - gem.version = "0.1.9" + gem.version = "0.2.0" gem.authors = "Steve Richert" gem.email = "steve.richert@gmail.com"