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: [], keywords: [], output: Output.new, on_git_error: nil) ⇒ 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 (Array<String>) (defaults to: [])

    file arguments provided directly via the -f or –files flag on the command line

  • keywords (Array<String>) (defaults to: [])

    reserved keywords that can potentially be translated to a list of files (e.g. ‘staged’, ‘modified’)

  • output (Output) (defaults to: Output.new)

    the console output handler

  • on_git_error (Proc, nil) (defaults to: nil)

    callback invoked with the error message when a git command fails (nil silently swallows the error)



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

def initialize(provided: [], keywords: [], output: Output.new, on_git_error: nil)
  @provided = Array(provided)
  @keywords = Array(keywords)
  @output = output
  @on_git_error = on_git_error
end

Instance Attribute Details

#keywordsObject (readonly)

Returns the value of attribute keywords.



10
11
12
# File 'lib/reviewer/arguments/files.rb', line 10

def keywords
  @keywords
end

#providedObject (readonly) Also known as: raw

Returns the value of attribute provided.



10
11
12
# File 'lib/reviewer/arguments/files.rb', line 10

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



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

def to_a = file_list

#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



51
52
53
54
55
56
# File 'lib/reviewer/arguments/files.rb', line 51

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 file values



46
# File 'lib/reviewer/arguments/files.rb', line 46

def to_s = to_a.join(',')