Sha256: d99c92b1d8bd995a528b716cda8c70a9268d0b54c70f37a719007bb55e3dfd78

Contents?: true

Size: 963 Bytes

Versions: 2

Compression:

Stored size: 963 Bytes

Contents

require 'reek/source'

module Reek
  module CLI
    #
    # CLI Input utility
    #
    module Input
      def sources
        if input_was_piped?
          source_from_pipe
        else
          if no_source_files_given?
            working_directory_as_source
          else
            sources_from_argv
          end
        end
      end

      private

      def input_was_piped?
        !$stdin.tty?
      end

      def no_source_files_given?
        # At this point we have deleted all options from @argv. The only remaining entries
        # are paths to the source files. If @argv is empty, this means that no files were given.
        @argv.empty?
      end

      def working_directory_as_source
        Source::SourceLocator.new(['.']).all_sources
      end

      def sources_from_argv
        Source::SourceLocator.new(@argv).all_sources
      end

      def source_from_pipe
        [$stdin.to_reek_source('$stdin')]
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
reek-1.6.3 lib/reek/cli/input.rb
reek-1.6.2 lib/reek/cli/input.rb