lib/lapidarius/cutter.rb in lapidarius-3.3.0 vs lib/lapidarius/cutter.rb in lapidarius-3.4.0

- old
+ new

@@ -1,41 +1,45 @@ require "lapidarius/gem" require "lapidarius/command" +require "rubygems/requirement" module Lapidarius class Cutter DEVELOPMENT = "development" - def initialize(name, cmd_klass = Command) + attr_reader :version + + def initialize(name:, cmd_klass: Command, version: nil) @name = name @cmd = cmd_klass.new + @version = version @dev_deps = [] end 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) + private def recurse(name = @name, gem = nil, version = @version) + tokens = tokenize(name, version) token = tokens.shift gem ||= Gem.factory(token) tokens.each do |t| next unless dep = Gem.factory(t) gem << dep - recurse(dep.name, dep) + recurse(dep.name, dep, nil) end gem end def dev_count @dev_deps.map { |e| e.split(" ").first }.uniq.count end - private def tokenize(name) - src = @cmd.call(name) + private def tokenize(name, version) + src = @cmd.call(name, version) data = normalize(src) dev, tokens = data.partition { |token| token.match(/#{DEVELOPMENT}/) } @dev_deps.concat(dev) tokens end