lib/lapidarius/cutter.rb in lapidarius-4.4.4 vs lib/lapidarius/cutter.rb in lapidarius-4.5.5
- old
+ new
@@ -22,34 +22,38 @@
end
end
private def recurse(name: @name, gem: nil, version: @version)
tokens = tokenize(name, version, @remote)
- token = tokens.shift
- gem ||= Gem.factory(token)
- tokens.each do |t|
- next unless dep = Gem.factory(t)
- gem << @cache.fetch(t) do
- recurse(name: dep.name, gem: dep, version: dep.version)
- @cache[t] = dep
- end
+ parent = tokens.shift
+ gem ||= Gem.factory(parent)
+ tokens.reduce(gem) do |acc, token|
+ acc << dependency(token); acc
end
- gem
end
def dev_count
@dev_deps.map { |e| e.split(" ").first }.uniq.count
end
+ private def dependency(token)
+ @cache.fetch(token) do
+ Gem.factory(token).tap do |dep|
+ recurse(name: dep.name, gem: dep, version: dep.version)
+ @cache[token] = dep
+ end
+ end
+ end
+
private def tokenize(name, version, remote)
src = @cmd.call(name, version, remote)
- data = normalize(src)
+ data = latest_match(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)
+ private def latest_match(src)
+ src.split(/\n\n/).map!(&:strip).last.split("\n").map(&:strip)
end
end
end