Sha256: 50707f84d462ec3e1b25b464f4c7d02dd7c39fd660f43efa87b5e009e8920030

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

require "lapidarius/gem"
require "lapidarius/command"

module Lapidarius
  class Cutter
    DEVELOPMENT = "development"

    def initialize(name, cmd_klass = Command)
      @name = name
      @cmd = cmd_klass.new
      @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)
      token = tokens.shift
      gem ||= Gem.factory(token)
      tokens.each do |t|
        next unless dep = Gem.factory(t)
        gem << 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 = 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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
lapidarius-3.3.0 lib/lapidarius/cutter.rb
lapidarius-3.2.1 lib/lapidarius/cutter.rb
lapidarius-3.2.0 lib/lapidarius/cutter.rb