Class: SystemCommand::Result

Inherits:
Object
  • Object
show all
Defined in:
brew/Library/Homebrew/system_command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, output, status) ⇒ Result

Returns a new instance of Result



176
177
178
179
180
181
# File 'brew/Library/Homebrew/system_command.rb', line 176

def initialize(command, output, status)
  @command       = command
  @output        = output
  @status        = status
  @exit_status   = status.exitstatus
end

Instance Attribute Details

#commandObject

Returns the value of attribute command



174
175
176
# File 'brew/Library/Homebrew/system_command.rb', line 174

def command
  @command
end

#exit_statusObject

Returns the value of attribute exit_status



174
175
176
# File 'brew/Library/Homebrew/system_command.rb', line 174

def exit_status
  @exit_status
end

#statusObject

Returns the value of attribute status



174
175
176
# File 'brew/Library/Homebrew/system_command.rb', line 174

def status
  @status
end

Instance Method Details

#merged_outputObject



195
196
197
198
# File 'brew/Library/Homebrew/system_command.rb', line 195

def merged_output
  @merged_output ||= @output.map { |_, line| line }
                            .join
end

#plistObject



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'brew/Library/Homebrew/system_command.rb', line 210

def plist
  @plist ||= begin
    output = stdout

    if /\A(?<garbage>.*?)<\?\s*xml/m =~ output
      output = output.sub(/\A#{Regexp.escape(garbage)}/m, "")
      warn_plist_garbage(garbage)
    end

    if %r{<\s*/\s*plist\s*>(?<garbage>.*?)\Z}m =~ output
      output = output.sub(/#{Regexp.escape(garbage)}\Z/, "")
      warn_plist_garbage(garbage)
    end

    Plist.parse_xml(output)
  end
end

#stderrObject



189
190
191
192
193
# File 'brew/Library/Homebrew/system_command.rb', line 189

def stderr
  @stderr ||= @output.select { |type,| type == :stderr }
                     .map { |_, line| line }
                     .join
end

#stdoutObject



183
184
185
186
187
# File 'brew/Library/Homebrew/system_command.rb', line 183

def stdout
  @stdout ||= @output.select { |type,| type == :stdout }
                     .map { |_, line| line }
                     .join
end

#success?Boolean

Returns:

  • (Boolean)


200
201
202
203
204
# File 'brew/Library/Homebrew/system_command.rb', line 200

def success?
  return false if @exit_status.nil?

  @exit_status.zero?
end

#to_aryObject



206
207
208
# File 'brew/Library/Homebrew/system_command.rb', line 206

def to_ary
  [stdout, stderr, status]
end