Class: CommandExec::Formatter::Hash

Inherits:
Object
  • Object
show all
Includes:
CommandExec::FieldHelper
Defined in:
lib/command_exec/formatter/hash.rb

Overview

Style hash

Direct Known Subclasses

JSON, XML, YAML

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CommandExec::FieldHelper

#end_time, #executable, #log_file, #pid, #reason_for_failure, #return_code, #start_time, #stderr, #stdout

Constructor Details

#initialize(options = {}) ⇒ Hash

Create new hash formatter

Parameters:

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

    Options for formatter

Options Hash (options):

  • :logger (Symbol)

    Logger to output information. Needs to have the same interface like the ruby Logger-class.



29
30
31
32
33
34
35
36
37
# File 'lib/command_exec/formatter/hash.rb', line 29

def initialize(options={})
  @options = {
    logger: Logger.new($stdout),
  }.deep_merge options

  @logger = @options[:logger]

  super()
end

Instance Attribute Details

#logger=(value) ⇒ Object (writeonly)

Sets the attribute logger

Parameters:

  • value

    the value to set the attribute logger to.



17
18
19
# File 'lib/command_exec/formatter/hash.rb', line 17

def logger=(value)
  @logger = value
end

#output(*fields) ⇒ Hash (readonly)

Output the prepared output

Parameters:

  • fields (Array, Symbol)

    the fields which should be outputted

Returns:

  • (Hash)

    the formatted output



14
15
16
# File 'lib/command_exec/formatter/hash.rb', line 14

def output
  @output
end

Instance Method Details

#status(value) ⇒ Object



39
40
41
# File 'lib/command_exec/formatter/hash.rb', line 39

def status(value)
  prepare_status(value)
end