Sha256: 556ab59bdc0cbdd0e7e8f11418e6f16670b314807c66dca7e47f1da5bf67952f

Contents?: true

Size: 930 Bytes

Versions: 1

Compression:

Stored size: 930 Bytes

Contents

# frozen_string_literal: true

module Umwelt::Tree
  class Imprint
    include Hanami::Interactor

    expose :written_paths

    def initialize(trunk, location: nil)
      @trunk = trunk
      @location = location
      @written_paths = {}
    end

    def call(semantic_name)
      error! not_clean unless location_clean?

      @trunk.nodes.map do |node|
        write node.semantic(semantic_name)
      end
    end

    private

    def write(semantic)
      path = semantic.path(location: @location)

      path.dirname.mkpath

      count = path.write(semantic.code)

      @written_paths[path] = count
    end

    def location_clean?
      imprint_root.mkpath
      imprint_root.empty?
    end

    def not_clean
      <<~WARN_MESSAGE
        #{imprint_root} contain files.
        Try use another --target, or delete them.
      WARN_MESSAGE
    end

    def imprint_root
      Pathname.pwd / @location
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
umwelt-0.1.1 lib/umwelt/tree/imprint.rb