class Umwelt::Tree::Imprint

Public Class Methods

new(trunk, location: nil) click to toggle source
# File lib/umwelt/tree/imprint.rb, line 7
def initialize(trunk, location: nil)
  @trunk = trunk
  @location = location
  @written_paths = {}
end

Public Instance Methods

call(semantic_name) click to toggle source
# File lib/umwelt/tree/imprint.rb, line 13
def call(semantic_name)
  error! not_clean unless location_clean?

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

Private Instance Methods

imprint_root() click to toggle source
# File lib/umwelt/tree/imprint.rb, line 45
def imprint_root
  Pathname.pwd / @location
end
location_clean?() click to toggle source
# File lib/umwelt/tree/imprint.rb, line 33
def location_clean?
  imprint_root.mkpath
  imprint_root.empty?
end
not_clean() click to toggle source
# File lib/umwelt/tree/imprint.rb, line 38
    def not_clean
      <<~WARN_MESSAGE
        #{imprint_root} contain files.
        Try use another --target, or delete them.
      WARN_MESSAGE
    end
write(semantic) click to toggle source
# File lib/umwelt/tree/imprint.rb, line 23
def write(semantic)
  path = semantic.path(location: @location)

  path.dirname.mkpath

  count = path.write(semantic.code)

  @written_paths[path] = count
end