Class: Mutant::Output

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-mutant/output.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(success = true, errors = [], meta = {}) ⇒ Output

Output constructor

Parameters:

success

The successful state of the mutation that owns this object. (defaults to ‘true`)

errors

An array of errors that can be packaged and wrapped in this object to be ‘returned` from the mutation’s ‘execute` method. (defaults to `[]`)

meta

A hash map that can be used to set any information that needs to be returned from the mutation to the calling code. (defaults to ‘{}`)



25
26
27
28
29
# File 'lib/ruby-mutant/output.rb', line 25

def initialize(success=true, errors=[], meta={})
    @success = success
    @errors = errors
    @meta = meta
end

Instance Attribute Details

#errorsArray

Returns The get/set for the mutations errors that have been thrown.

Returns:

  • (Array)

    The get/set for the mutations errors that have been thrown



11
12
13
# File 'lib/ruby-mutant/output.rb', line 11

def errors
  @errors
end

#metaHash

Returns the hash of metadata the user wants returned from the mutation execution.

Returns:

  • (Hash)

    the hash of metadata the user wants returned from the mutation execution



8
9
10
# File 'lib/ruby-mutant/output.rb', line 8

def meta
  @meta
end

#successObject (readonly)

Allows to reading the status of the executed mutation



5
6
7
# File 'lib/ruby-mutant/output.rb', line 5

def success
  @success
end

Instance Method Details

#add_meta(key, value) ⇒ Object

Adds meta data to the @meta hash (will overwrite existing value)

Parameters:

key

A symbol that will be used to store the value in the hash

value

Any value that you wish to store indexed by the ‘key` param. This can be used if you need to return data from the mutation’s ‘execute` method

Returns:

Nothing useful


44
45
46
# File 'lib/ruby-mutant/output.rb', line 44

def add_meta(key, value)
    @meta[key] = value
end

#success?Boolean

Helper method to determine successfulnes of the mutation that has ran. A successful mutation execution is defined by having an error count of 0. TODO: This needs to be handled better, more smart about what success means

Parameters:

Returns:

A boolean that represents the status of the just execute mutation

Returns:

  • (Boolean)


56
57
58
# File 'lib/ruby-mutant/output.rb', line 56

def success?
    @success
end