Sha256: 38460ebf05f2367200c29dc67e6b4af219189a8a9ae78d5145ba15d88e287a4f

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

require_relative 'source_code'
require_relative 'source_locator'

module Reek
  module Source
    #
    # A collection of source code. If the collection is initialized with an array
    # it is assumed to be a list of file paths. Otherwise it is assumed to be a
    # single unit of Ruby source code.
    #
    class SourceRepository
      # TODO: This method is a least partially broken.
      # Regardless of how you call reek, be it:
      #   reek lib/
      #   reek lib/file_one.rb lib/file_two.rb
      #   echo "def m; end" | reek
      # we *always* end up in the "when Source::SourceCode" branch.
      # So it seems like 80% of this method is never used.
      def self.parse(source)
        case source
        when Array
          new 'dir', Source::SourceLocator.new(source).all_sources
        when Source::SourceCode
          new source.desc, [source]
        else
          src = Source::SourceCode.from source
          new src.desc, [src]
        end
      end

      include Enumerable
      attr_reader :description

      def initialize(description, sources)
        @description = description
        @sources = sources
      end

      def each(&block)
        @sources.each(&block)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
reek-2.1.0 lib/reek/source/source_repository.rb