Method: Label.process
- Defined in:
- lib/label.rb
.process(gemfile, describing = nil, described = nil) ⇒ Object
Process the given Gemfile.
gemfile - A String describing the path to a Gemfile. describing - A Proc to be called once a query to describe a gem begins.
Receives the name of the gem as an argument.
described - A Proc to be called once a query to describe a gem completes.
Receives the description as an argument.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/label.rb', line 28 def process gemfile, describing = nil, described = nil file = read gemfile lines = file.read.split "\n" processed_lines = [] lines.each_with_index do |line, i| matches = line.match /^( *)gem ['"](.+?)['"]/ if matches previous_line = lines[i - 1] whitespace = matches[1] gem = matches[2] source = line unless previous_line =~ /^ *#/ describing.call gem if describing description = describe gem, source described.call description if described processed_lines << format(description, "#{whitespace}#") end end processed_lines << line end processed_lines.join("\n") + "\n" end |