Class: Reviewer::Keywords::Git::Staged

Inherits:
Object
  • Object
show all
Defined in:
lib/reviewer/keywords/git/staged.rb

Overview

Provides a convenient interface to get the list of staged files via Git

Constant Summary collapse

OPTIONS =
[
  'diff',
  '--staged',
  '--name-only'
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#exit_statusObject (readonly)

Returns the value of attribute exit_status.



14
15
16
# File 'lib/reviewer/keywords/git/staged.rb', line 14

def exit_status
  @exit_status
end

#statusObject (readonly)

Returns the value of attribute status.



14
15
16
# File 'lib/reviewer/keywords/git/staged.rb', line 14

def status
  @status
end

#stderrObject (readonly)

Returns the value of attribute stderr.



14
15
16
# File 'lib/reviewer/keywords/git/staged.rb', line 14

def stderr
  @stderr
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



14
15
16
# File 'lib/reviewer/keywords/git/staged.rb', line 14

def stdout
  @stdout
end

Class Method Details

.listArray<String>

Convenience method for retrieving the list of staged files since there’s no parameters

for an initializer.

Examples:

Get the list of files

Reviewer::Keywords::Git::Staged.list #=> ['/Code/example.rb', '/Code/run.rb']

Returns:

  • (Array<String>)

    the array of staged filenames as strings



40
41
42
# File 'lib/reviewer/keywords/git/staged.rb', line 40

def self.list
  new.list
end

Instance Method Details

#commandString

Assembles the pieces of the command that gets the list of staged files

Returns:

  • (String)

    the full command to run to retrieve the list of staged files



47
48
49
# File 'lib/reviewer/keywords/git/staged.rb', line 47

def command
  command_parts.join(' ')
end

#listArray<String>

Gets the list of staged files

Examples:

Get the list of files

staged.list #=> ['/Code/example.rb', '/Code/run.rb']

Returns:

  • (Array<String>)

    the array of staged filenames as strings



26
27
28
29
30
31
# File 'lib/reviewer/keywords/git/staged.rb', line 26

def list
  @stdout, @stderr, @status = Open3.capture3(command)
  @exit_status = @status.exitstatus.to_i

  @status.success? ? to_a : raise_command_line_error
end

#to_aObject



16
17
18
# File 'lib/reviewer/keywords/git/staged.rb', line 16

def to_a
  stdout.strip.empty? ? [] : stdout.split("\n")
end