Sha256: 6745f529a701b11cab0712e13ced6f7360988d214dd39ed89ada23138a124ca3

Contents?: true

Size: 956 Bytes

Versions: 3

Compression:

Stored size: 956 Bytes

Contents

# frozen_string_literal: true

require "refinements/pathnames"

module Pragmater
  # Adds/removes pragma comments for files in given path.
  class Runner
    include Import[:logger]

    using Refinements::Pathnames

    def initialize(parser: Parsers::File.new, **)
      super(**)
      @parser = parser
    end

    def call configuration = Container[:configuration]
      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

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pragmater-12.2.0 lib/pragmater/runner.rb
pragmater-12.1.2 lib/pragmater/runner.rb
pragmater-12.1.1 lib/pragmater/runner.rb