Skip to content

Commit

Permalink
Handle gemfile group options
Browse files Browse the repository at this point in the history
  • Loading branch information
laserlemon committed Dec 14, 2011
1 parent d226efc commit cf3fbad
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
30 changes: 18 additions & 12 deletions lib/gemnasium/parser/patterns.rb
Expand Up @@ -23,19 +23,25 @@ module Patterns
GEMSPEC_CALL = /^\s*gemspec(?:\s+(?<opts>#{OPTIONS}))?\s*$/

def self.options(string)
return {} unless string
hash, raw = {}, Hash[*string.match(OPTIONS).captures.compact]
raw.each do |key, value|
new_key = key.tr(%(:"'), "")
new_value = case value
when BOOLEAN then value == "true"
when NIL then nil
when SYMBOL then value.tr(%(:"'), "").to_sym
when STRING then value.tr(%("'), "")
end
hash[new_key] = new_value
{}.tap do |hash|
return hash unless string
pairs = Hash[*string.match(OPTIONS).captures.compact]
pairs.each{|k,v| hash[key(k)] = value(v) }
end
end

def self.key(string)
string.tr(%(:"'), "")
end

def self.value(string)
case string
when NIL then nil
when BOOLEAN then string == "true"
when ARRAY then string.tr("[]", "").split(/\s*,\s*/).map{|e| value(e) }
when SYMBOL then string.tr(%(:"'), "").to_sym
when STRING then string.tr(%("'), "")
end
hash
end
end
end
Expand Down
13 changes: 13 additions & 0 deletions spec/gemnasium/parser/gemfile_spec.rb
Expand Up @@ -89,4 +89,17 @@ def reset
content(%(gem "rake", :type => :development))
dependency.type.should == :development
end

it "parses gems of a group" do
content(%(gem "rake"))
dependency.groups.should == [:default]
reset
content(%(gem "rake", :group => :development))
dependency.groups.should == [:development]
end

it "parses gems of multiple groups" do
content(%(gem "rake", :group => [:development, :test]))
dependency.groups.should == [:development, :test]
end
end

0 comments on commit cf3fbad

Please sign in to comment.