Sha256: fbe65f5df20835770a21526d397ffaab0336ffebefa01db772c3ad20df1b6a88

Contents?: true

Size: 1.34 KB

Versions: 5

Compression:

Stored size: 1.34 KB

Contents

module Steep
  module Services
    class FileLoader
      attr_reader :base_dir

      def initialize(base_dir:)
        @base_dir = base_dir
      end

      def each_path_in_patterns(pattern, commandline_patterns = [])
        pats = commandline_patterns.empty? ? pattern.patterns : commandline_patterns

        pats.each do |path|
          absolute_path = base_dir + path

          if absolute_path.file?
            yield absolute_path.relative_path_from(base_dir)
          else
            files = if absolute_path.directory?
                      Pathname.glob("#{absolute_path}/**/*#{pattern.ext}")
                    else
                      Pathname.glob(absolute_path)
                    end

            files.sort.each do |source_path|
              if source_path.file?
                relative_path = source_path.relative_path_from(base_dir)
                unless pattern.ignore?(relative_path)
                  yield relative_path
                end
              end
            end
          end
        end
      end

      def load_changes(pattern, command_line_patterns = [], changes:)
        each_path_in_patterns(pattern, command_line_patterns) do |path|
          unless changes.key?(path)
            changes[path] = [ContentChange.string((base_dir + path).read)]
          end
        end

        changes
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
steep-0.44.1 lib/steep/services/file_loader.rb
steep-0.44.0 lib/steep/services/file_loader.rb
steep-0.43.1 lib/steep/services/file_loader.rb
steep-0.43.0 lib/steep/services/file_loader.rb
steep-0.42.0 lib/steep/services/file_loader.rb