Sha256: 37237705f007444efca7f3ec216d3fd56a0dc50a28558a15573b6f45d37d93e5

Contents?: true

Size: 1.92 KB

Versions: 10

Compression:

Stored size: 1.92 KB

Contents

module Steep
  class Project
    class FileLoader
      attr_reader :project

      def initialize(project:)
        @project = project
      end

      def each_path_in_patterns(patterns, ext)
        patterns.each do |path|
          absolute_path = project.base_dir + path

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

            files.each do |source_path|
              yield project.relative_path(source_path)
            end
          end
        end
      end

      def load_sources(command_line_patterns)
        project.targets.each do |target|
          Steep.logger.tagged "target=#{target.name}" do
            target_patterns = command_line_patterns.empty? ? target.source_patterns : command_line_patterns

            each_path_in_patterns target_patterns, ".rb" do |path|
              if target.possible_source_file?(path)
                unless target.source_file?(path)
                  Steep.logger.info { "Adding source file: #{path}" }
                  target.add_source path, project.absolute_path(path).read
                end
              end
            end
          end
        end
      end

      def load_signatures()
        project.targets.each do |target|
          Steep.logger.tagged "target=#{target.name}" do
            each_path_in_patterns target.signature_patterns, ".rbs" do |path|
              if target.possible_signature_file?(path)
                unless target.signature_file?(path)
                  Steep.logger.info { "Adding signature file: #{path}" }
                  target.add_signature path, project.absolute_path(path).read
                end
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
steep-0.17.1 lib/steep/project/file_loader.rb
steep-0.17.0 lib/steep/project/file_loader.rb
steep-0.16.3 lib/steep/project/file_loader.rb
steep-0.16.2 lib/steep/project/file_loader.rb
steep-0.16.1 lib/steep/project/file_loader.rb
steep-0.16.0 lib/steep/project/file_loader.rb
steep-0.15.0 lib/steep/project/file_loader.rb
steep-0.14.0 lib/steep/project/file_loader.rb
steep-0.13.0 lib/steep/project/file_loader.rb
steep-0.12.0 lib/steep/project/file_loader.rb