Sha256: 111b289599ab6899a6f4d3b79b3a20d0a32fd4ac03af7331758933a8fe620e89

Contents?: true

Size: 743 Bytes

Versions: 3

Compression:

Stored size: 743 Bytes

Contents

# frozen_string_literal: true

require "pathname"

module Tocer
  # Generates/updates Table of Contents for files in given path.
  class Runner
    def initialize path = "", configuration: {}, writer: Writer
      @path = Pathname path
      @configuration = configuration
      @writer = writer
    end

    def files
      return [] unless path.exist?
      glob = whitelist.empty? ? %(#{path}/**/*) : %(#{path}/**/*{#{whitelist.join ","}})
      Pathname.glob(glob).select(&:file?)
    end

    def run
      files.each { |file| writer.new(file, label: configuration.fetch(:label)).write }
    end

    private

    attr_reader :path, :configuration, :writer

    def whitelist
      Array configuration.fetch(:whitelist)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tocer-4.0.0 lib/tocer/runner.rb
tocer-3.3.0 lib/tocer/runner.rb
tocer-3.2.0 lib/tocer/runner.rb