Skip to content
This repository was archived by the owner on Jul 15, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -10,7 +14,7 @@ Bugfixes:

* support :github option and exclude gems that use it
* add CHANGELOG

## 0.1.7 2012-10-17

Bugfixes:
Expand Down
2 changes: 1 addition & 1 deletion gemnasium-parser.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 9 additions & 0 deletions lib/gemnasium/parser/gemfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions lib/gemnasium/parser/patterns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ module Patterns

ADD_DEPENDENCY_CALL = /^[ \t]*\w+\.add(?<type>_runtime|_development)?_dependency\(?[ \t]*#{QUOTED_GEM_NAME}(?:[ \t]*,[ \t]*#{REQUIREMENTS})?[ \t]*\)?[ \t]*#{COMMENT}$/

QUOTED_RUBY_VERSION = /(?:(?<gq>["'])(?<version>#{VERSION})\k<gq>|%q<(?<version>#{VERSION})>)/
RUBY_CALL = /^[ \t]*ruby\(?[ \t]*#{QUOTED_RUBY_VERSION}(?:[ \t]*,[ \t]*(?<opts>#{OPTIONS}))?[ \t]*\)?[ \t]*#{COMMENT}$/

def self.options(string)
{}.tap do |hash|
return hash unless string
Expand Down
15 changes: 15 additions & 0 deletions spec/gemnasium/parser/gemfile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down