Sha256: 203cbfc3a34bd8666deabe7b3ea06abef219d298cedbc9e07b9204523ea3dc9f

Contents?: true

Size: 1.13 KB

Versions: 4

Compression:

Stored size: 1.13 KB

Contents

module Munge
  class Runner
    def initialize(items:, router:, processor:, writer:, formatter:, verbosity:, destination:)
      @items         = items
      @router        = router
      @processor     = processor
      @writer        = writer
      @reporter      = Munge::Reporter.new(formatter: formatter, verbosity: verbosity)
      @write_manager = Munge::WriteManager.new(driver: File)
      @destination   = destination
    end

    def write
      @reporter.start

      @items
        .reject { |item| item.route.nil? }
        .each   { |item| render_and_write(item) }

      @reporter.done
    end

    private

    def render_and_write(item)
      relpath = @router.filepath(item)
      abspath = File.join(@destination, relpath)
      content = @processor.transform(item)

      write_status = @write_manager.status(abspath, content)

      case write_status
      when :new, :changed
        @writer.write(abspath, content)
      when :double_write_error
        raise Errors::DoubleWriteError, item.route
      when :identical
        # Defer to the reporter
      end

      @reporter.call(item, relpath, write_status)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
munge-0.15.1 lib/munge/runner.rb
munge-0.15.0 lib/munge/runner.rb
munge-0.14.0 lib/munge/runner.rb
munge-0.13.0 lib/munge/runner.rb