Sha256: fa982958cfa7552328606367a3edbb0c88fe60704434fd5e48495fd3cc6b5bf8

Contents?: true

Size: 1.56 KB

Versions: 15

Compression:

Stored size: 1.56 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?
              if pattern =~ path
                yield absolute_path.relative_path_from(base_dir)
              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

15 entries across 15 versions & 1 rubygems

Version Path
steep-1.6.0 lib/steep/services/file_loader.rb
steep-1.6.0.pre.4 lib/steep/services/file_loader.rb
steep-1.6.0.pre.3 lib/steep/services/file_loader.rb
steep-1.6.0.pre.2 lib/steep/services/file_loader.rb
steep-1.6.0.pre.1 lib/steep/services/file_loader.rb
steep-1.5.3 lib/steep/services/file_loader.rb
steep-1.5.2 lib/steep/services/file_loader.rb
steep-1.5.1 lib/steep/services/file_loader.rb
steep-1.5.0 lib/steep/services/file_loader.rb
steep-1.5.0.pre.6 lib/steep/services/file_loader.rb
steep-1.5.0.pre.5 lib/steep/services/file_loader.rb
steep-1.5.0.pre.4 lib/steep/services/file_loader.rb
steep-1.5.0.pre.3 lib/steep/services/file_loader.rb
steep-1.5.0.pre.2 lib/steep/services/file_loader.rb
steep-1.5.0.pre.1 lib/steep/services/file_loader.rb