lib/lapidarius/cutter.rb in lapidarius-3.1.2 vs lib/lapidarius/cutter.rb in lapidarius-3.2.0
- old
+ new
@@ -3,36 +3,46 @@
module Lapidarius
class Cutter
DEVELOPMENT = "development"
- class GemNotCreatedError < StandardError; end
-
def initialize(name, cmd_klass = Command)
@name = name
@cmd = cmd_klass.new
+ @dev_deps = []
end
- def call(name = @name, gem = nil)
+ def call
+ recurse.tap do |gem|
+ gem.dev_count = dev_count if gem
+ end
+ end
+
+ private def recurse(name = @name, gem = nil)
tokens = tokenize(name)
token = tokens.shift
gem ||= Gem.factory(token)
- fail GemNotCreatedError, "unable to create a gem from #{token}" unless gem
tokens.each do |t|
- dep = Gem.factory(t)
- next unless dep
+ next unless dep = Gem.factory(t)
gem << dep
- call(dep.name, dep)
+ recurse(dep.name, dep)
end
gem
end
+ def dev_count
+ @dev_deps.map { |e| e.split(" ").first }.uniq.count
+ end
+
private def tokenize(name)
src = @cmd.call(name)
- data = src.split(/\n\n/).map!(&:strip)
- data.first.split("\n").tap do |tokens|
- tokens.map!(&:strip)
- tokens.reject! { |token| token.match(/#{DEVELOPMENT}/) }
- end
+ data = normalize(src)
+ dev, tokens = data.partition { |token| token.match(/#{DEVELOPMENT}/) }
+ @dev_deps.concat(dev)
+ tokens
+ end
+
+ private def normalize(src)
+ src.split(/\n\n/).map!(&:strip).first.split("\n").map(&:strip)
end
end
end