Sha256: 75ec0d0c3aaceb390fa3859975259819b561dd56245adbe7ea5b6b36916add7c

Contents?: true

Size: 1.52 KB

Versions: 10

Compression:

Stored size: 1.52 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|
            Pathname.glob((base_dir + path).to_s).each do |absolute_path|
              if absolute_path.file?
                relative_path = absolute_path.relative_path_from(base_dir)
                if pattern =~ relative_path
                  yield relative_path
                end
              else
                files = Pathname.glob("#{absolute_path}/**/*#{pattern.ext}")

                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
        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

10 entries across 10 versions & 1 rubygems

Version Path
steep-1.8.3 lib/steep/services/file_loader.rb
steep-1.8.2 lib/steep/services/file_loader.rb
steep-1.8.1 lib/steep/services/file_loader.rb
steep-1.8.0 lib/steep/services/file_loader.rb
steep-1.8.0.pre.2 lib/steep/services/file_loader.rb
steep-1.8.0.pre.1 lib/steep/services/file_loader.rb
steep-1.8.0.dev.2 lib/steep/services/file_loader.rb
steep-1.8.0.dev.1 lib/steep/services/file_loader.rb
steep-1.7.1 lib/steep/services/file_loader.rb
steep-1.7.0 lib/steep/services/file_loader.rb