Class: Reviewer::Keywords::Git::Staged
- Inherits:
-
Object
- Object
- Reviewer::Keywords::Git::Staged
- 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
-
#exit_status ⇒ Object
readonly
Returns the value of attribute exit_status.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#stderr ⇒ Object
readonly
Returns the value of attribute stderr.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
Class Method Summary collapse
-
.list ⇒ Array<String>
Convenience method for retrieving the list of staged files since there’s no parameters for an initializer.
Instance Method Summary collapse
-
#command ⇒ String
Assembles the pieces of the command that gets the list of staged files.
-
#list ⇒ Array<String>
Gets the list of staged files.
- #to_a ⇒ Object
Instance Attribute Details
#exit_status ⇒ Object (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 |
#status ⇒ Object (readonly)
Returns the value of attribute status.
14 15 16 |
# File 'lib/reviewer/keywords/git/staged.rb', line 14 def status @status end |
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
14 15 16 |
# File 'lib/reviewer/keywords/git/staged.rb', line 14 def stderr @stderr end |
#stdout ⇒ Object (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
.list ⇒ Array<String>
Convenience method for retrieving the list of staged files since there’s no parameters
for an initializer.
40 41 42 |
# File 'lib/reviewer/keywords/git/staged.rb', line 40 def self.list new.list end |
Instance Method Details
#command ⇒ String
Assembles the pieces of the command that gets the list of staged files
47 48 49 |
# File 'lib/reviewer/keywords/git/staged.rb', line 47 def command command_parts.join(' ') end |
#list ⇒ Array<String>
Gets the list of staged files
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_a ⇒ Object
16 17 18 |
# File 'lib/reviewer/keywords/git/staged.rb', line 16 def to_a stdout.strip.empty? ? [] : stdout.split("\n") end |