Class: CommandExec::Process

Inherits:
Object
  • Object
show all
Includes:
FieldHelper
Defined in:
lib/command_exec/process.rb

Overview

The class used to save the data about the executed command

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Process

Create a process object

Parameters:

  • options (Hash) (defaults to: {})

    options for the process

Options Hash (options):

  • lib_logger (Logger)

    The logger which is used to output information generated by the library. The logger which is provided needs to be compatible with api of the Ruby Logger-class.

  • stderr (Array)

    content of stderr of the process

  • stdout (Array)

    content of stdout of the process

  • log_file (Array)

    content of the log file of the process

  • pid (Number, String)

    the pid of the process

  • return_code (Number, String)

    the exit status of the process

  • reason_for_failure (Array)

    the reason for failure

  • status (Symbol)

    execution was successful, failed



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/command_exec/process.rb', line 70

def initialize(options={})
  @options = {
    lib_logger: Logger.new($stderr),
    stderr: [],
    stdout: [],
    log_file: [],
    pid: nil,
    return_code: nil,
    reason_for_failure: [],
    status: :success,
    executable: nil,
  }.merge options

  @logger = @options[:lib_logger]

  @stderr = @options[:stderr]
  @stdout = @options[:stdout]
  @status = @options[:status]
  @log_file = @options[:log_file]
  @pid = @options[:pid]
  @reason_for_failure = @options[:reason_for_failure]
  @return_code = @options[:return_code]
  @executable = @options[:executable]

  @start_time = nil
  @end_time = nil
end

Instance Attribute Details

#end_timeObject

Returns the value of attribute end_time.



38
# File 'lib/command_exec/process.rb', line 38

attr_reader :status, :log_file, :stdout, :stderr, :reason_for_failure, :return_code, :pid, :start_time, :end_time

#executableObject

Set/Get the executable of the command



13
14
15
# File 'lib/command_exec/process.rb', line 13

def executable
  @executable
end

#log_fileObject

Returns the value of attribute log_file.



38
39
40
# File 'lib/command_exec/process.rb', line 38

def log_file
  @log_file
end

#pidObject

Get the pid of the command



38
# File 'lib/command_exec/process.rb', line 38

attr_reader :status, :log_file, :stdout, :stderr, :reason_for_failure, :return_code, :pid, :start_time, :end_time

#reason_for_failureObject

Get the reason why command_exec thinks a command failed



38
# File 'lib/command_exec/process.rb', line 38

attr_reader :status, :log_file, :stdout, :stderr, :reason_for_failure, :return_code, :pid, :start_time, :end_time

#return_codeObject

Get the exit code of the command



38
# File 'lib/command_exec/process.rb', line 38

attr_reader :status, :log_file, :stdout, :stderr, :reason_for_failure, :return_code, :pid, :start_time, :end_time

#start_timeObject

Return the time when the execution of the command started



38
# File 'lib/command_exec/process.rb', line 38

attr_reader :status, :log_file, :stdout, :stderr, :reason_for_failure, :return_code, :pid, :start_time, :end_time

#statusObject

Get the status of the command



38
39
40
# File 'lib/command_exec/process.rb', line 38

def status
  @status
end

#stderrObject

Get stderr of the command



38
# File 'lib/command_exec/process.rb', line 38

attr_reader :status, :log_file, :stdout, :stderr, :reason_for_failure, :return_code, :pid, :start_time, :end_time

#stdoutObject

Get stdout of the command



38
# File 'lib/command_exec/process.rb', line 38

attr_reader :status, :log_file, :stdout, :stderr, :reason_for_failure, :return_code, :pid, :start_time, :end_time

Instance Method Details

#run_timeObject



203
204
205
# File 'lib/command_exec/process.rb', line 203

def run_time
  end_time - start_time
end

#to_a(fields = default_fields, formatter = Formatter::Array.new) ⇒ Object

Output process data as array

Parameters:

  • fields (Array of Symbols) (defaults to: default_fields)

    the fields which should be outputed

  • formatter (Formatter) (defaults to: Formatter::Array.new)

    (Formatter::Array.new) the formatter which is used the format the output



234
235
236
# File 'lib/command_exec/process.rb', line 234

def to_a(fields=default_fields, formatter=Formatter::Array.new)
  output(fields, formatter)
end

#to_h(fields = default_fields, formatter = Formatter::Hash.new) ⇒ Object

Output process data as hash

Parameters:

  • fields (Array of Symbols) (defaults to: default_fields)

    the fields which should be outputed

  • formatter (Formatter) (defaults to: Formatter::Hash.new)

    (Formatter::Hash.new) the formatter which is used the format the output



245
246
247
# File 'lib/command_exec/process.rb', line 245

def to_h(fields=default_fields, formatter=Formatter::Hash.new)
  output(fields, formatter)
end

#to_json(fields = default_fields, formatter = Formatter::JSON.new) ⇒ Object

Output process data as json

Parameters:

  • fields (Array of Symbols) (defaults to: default_fields)

    the fields which should be outputed

  • formatter (Formatter) (defaults to: Formatter::JSON.new)

    (Formatter::JSON.new) the formatter which is used the format the output



278
279
280
# File 'lib/command_exec/process.rb', line 278

def to_json(fields=default_fields, formatter=Formatter::JSON.new)
  output(fields, formatter)
end

#to_s(fields = default_fields, formatter = Formatter::String.new) ⇒ Object

Output process data as string

Parameters:

  • fields (Array of Symbols) (defaults to: default_fields)

    the fields which should be outputed

  • formatter (Formatter) (defaults to: Formatter::String.new)

    (Formatter::String.new) the formatter which is used the format the output



256
257
258
# File 'lib/command_exec/process.rb', line 256

def to_s(fields=default_fields, formatter=Formatter::String.new)
  output(fields, formatter)
end

#to_xml(fields = default_fields, formatter = Formatter::XML.new) ⇒ Object

Output process data as xml

Parameters:

  • fields (Array of Symbols) (defaults to: default_fields)

    the fields which should be outputed

  • formatter (Formatter) (defaults to: Formatter::XML.new)

    (Formatter::XML.new) the formatter which is used the format the output



267
268
269
# File 'lib/command_exec/process.rb', line 267

def to_xml(fields=default_fields, formatter=Formatter::XML.new)
  output(fields, formatter)
end

#to_yaml(fields = default_fields, formatter = Formatter::YAML.new) ⇒ Object

Output process data as yaml

Parameters:

  • fields (Array of Symbols) (defaults to: default_fields)

    the fields which should be outputed

  • formatter (Formatter) (defaults to: Formatter::YAML.new)

    (Formatter::YAML.new) the formatter which is used the format the output



289
290
291
# File 'lib/command_exec/process.rb', line 289

def to_yaml(fields=default_fields, formatter=Formatter::YAML.new)
  output(fields, formatter)
end