Sha256: 500063122e31cea0223dfd2a69b77ead695f7cd83d34a38717fff0fd31df14a2

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

module Reviewer
  class Arguments
    # Generates the list of files to run the command against
    class Files
      attr_reader :provided, :keywords

      alias raw provided

      def initialize(provided: Reviewer.arguments.files.raw, keywords: Reviewer.arguments.keywords)
        @provided = Array(provided)
        @keywords = Array(keywords)
      end

      def to_a
        file_list
      end

      def to_s
        to_a.join(',')
      end

      def inspect
        {
          provided: provided,
          from_keywords: from_keywords
        }
      end

      private

      def file_list
        @file_list ||= [
          *provided,
          *from_keywords
        ].compact.sort.uniq
      end

      def from_keywords
        return [] unless keywords.any?

        keywords.map do |keyword|
          next unless respond_to?(keyword.to_sym, true)

          send(keyword.to_sym)
        end.flatten.uniq
      end

      def staged
        # Use git for list of staged fields
        ::Reviewer::Arguments::Keywords::Git::Staged.list
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
reviewer-0.1.3 lib/reviewer/arguments/files.rb