Sha256: b4086d26fb47a650f06eed6c0ffa3bb89282790d701628d2acfe6fec228c4b71

Contents?: true

Size: 1010 Bytes

Versions: 6

Compression:

Stored size: 1010 Bytes

Contents

# frozen_string_literal: true

require "refinements/pathnames"

module Pragmater
  # Adds/removes pragma comments for files in given path.
  class Runner
    using Refinements::Pathnames

    def initialize parser: Parsers::File.new, container: Container
      @parser = parser
      @container = container
    end

    def call configuration = Configuration::Loader.call
      Pathname(configuration.root_dir).files("{#{configuration.includes.join ","}}").map do |path|
        yield path if block_given?

        case configuration
          in action_insert: true then write path, configuration, :insert
          in action_remove: true then write path, configuration, :remove
          else logger.error { "Unknown run action. Use insert or remove." }
        end
      end
    end

    private

    attr_reader :parser, :container

    def write path, configuration, action
      path.write parser.call(path, configuration.comments, action:).join
    end

    def logger = container[__method__]
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
pragmater-10.3.1 lib/pragmater/runner.rb
pragmater-10.3.0 lib/pragmater/runner.rb
pragmater-10.2.0 lib/pragmater/runner.rb
pragmater-10.1.0 lib/pragmater/runner.rb
pragmater-10.0.1 lib/pragmater/runner.rb
pragmater-10.0.0 lib/pragmater/runner.rb