Class: Reviewer::Arguments::Files

Inherits:
Object
  • Object
show all
Defined in:
lib/reviewer/arguments/files.rb

Overview

Generates a Ruby-friendly list (Array) of files to run the command against from the provided command line arguments

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(provided: Reviewer.arguments.files.raw, keywords: Reviewer.arguments.keywords) ⇒ self

Generates an instance of files from the provided arguments

Examples:

Using the ‘-f` flag: `rvw -f ./file.rb`

reviewer = Reviewer::Arguments::Files.new(provided: ['./file.rb'], keywords: [])
reviewer.to_a # => ['./file.rb']

Using the ‘–files` flag: `rvw –files ./file.rb,./directory/file.rb

reviewer = Reviewer::Arguments::Files.new(provided: ['./file.rb','./directory/file.rb'], keywords: [])
reviewer.to_a # => ['./file.rb','./directory/file.rb']

Parameters:

  • provided: (defaults to: Reviewer.arguments.files.raw)

    Reviewer.arguments.files.raw [Array, String] file arguments provided directly via the -f or –files flag on the command line.

  • keywords: (defaults to: Reviewer.arguments.keywords)

    Reviewer.arguments.keywords [Array, String] keywords that can potentially be translated to a list of files (ex. ‘staged’)



26
27
28
29
# File 'lib/reviewer/arguments/files.rb', line 26

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

Instance Attribute Details

#keywordsObject (readonly)

Returns the value of attribute keywords.



8
9
10
# File 'lib/reviewer/arguments/files.rb', line 8

def keywords
  @keywords
end

#providedObject (readonly) Also known as: raw

Returns the value of attribute provided.



8
9
10
# File 'lib/reviewer/arguments/files.rb', line 8

def provided
  @provided
end

Instance Method Details

#to_aArray<String>

Provides the full list of file/path values derived from the command-line arguments

Returns:

  • (Array<String>)

    full collection of the file arguments as a string



34
35
36
# File 'lib/reviewer/arguments/files.rb', line 34

def to_a
  file_list
end

#to_hHash<Symbol, Array<String>> Also known as: inspect

Summary of the state of the file arguments

Returns:

  • (Hash<Symbol, Array<String>>)

    summarizes all of the resulting file values



48
49
50
51
52
53
# File 'lib/reviewer/arguments/files.rb', line 48

def to_h
  {
    provided: provided.sort,
    from_keywords: from_keywords
  }
end

#to_sString

Provides the full list of file/path values derived from the command-line arguments

Returns:

  • (String)

    comma-separated string of the derived tag values



41
42
43
# File 'lib/reviewer/arguments/files.rb', line 41

def to_s
  to_a.join(',')
end