Sha256: e5d784a12b15160285cb48e9820734e9876e249f4794c97bc79439413e57768e

Contents?: true

Size: 713 Bytes

Versions: 1

Compression:

Stored size: 713 Bytes

Contents

# frozen_string_literal: true

require "pathname"
require "refinements/pathnames"

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

    def self.for **attributes
      new Context[attributes]
    end

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

    def call
      Pathname(context.root_dir).files("{#{context.includes.join ","}}").map(&method(:write))
    end

    private

    attr_reader :context, :parser

    def write path
      path.tap do |a_path|
        a_path.write parser.call(a_path, context.comments, action: context.action).join
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pragmater-8.0.0 lib/pragmater/runner.rb