Sha256: 5797b83242c671d08f66939e50403d2aebedddb4aa65eeef7e41c4ea075d51df

Contents?: true

Size: 1.61 KB

Versions: 3

Compression:

Stored size: 1.61 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 = [])
        if block_given?
          pats = commandline_patterns.empty? ? pattern.patterns : commandline_patterns

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

            if absolute_path.file?
              relative_path = absolute_path.relative_path_from(base_dir)
              if pattern =~ relative_path
                yield relative_path
              end
            else
              files = if absolute_path.directory?
                        Pathname.glob("#{absolute_path}/**/*#{pattern.ext}")
                      else
                        Pathname.glob(absolute_path.to_s)
                      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
        else
          enum_for :each_path_in_patterns, pattern, commandline_patterns
        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

3 entries across 3 versions & 1 rubygems

Version Path
steep-1.7.0.dev.3 lib/steep/services/file_loader.rb
steep-1.7.0.dev.2 lib/steep/services/file_loader.rb
steep-1.7.0.dev.1 lib/steep/services/file_loader.rb