Class: Fluxo::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/fluxo/result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operation:, type:, value:, ids: nil) ⇒ Result

Returns a new instance of Result.

Parameters:

  • options (Hash)


12
13
14
15
16
17
# File 'lib/fluxo/result.rb', line 12

def initialize(operation:, type:, value:, ids: nil)
  @operation = operation
  @value = value
  @type = type
  @ids = Array(ids)
end

Instance Attribute Details

#idsObject (readonly)

Returns the value of attribute ids.



5
6
7
# File 'lib/fluxo/result.rb', line 5

def ids
  @ids
end

#operationObject (readonly)

Returns the value of attribute operation.



5
6
7
# File 'lib/fluxo/result.rb', line 5

def operation
  @operation
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/fluxo/result.rb', line 5

def type
  @type
end

#valueObject (readonly)

Returns the value of attribute value.



5
6
7
# File 'lib/fluxo/result.rb', line 5

def value
  @value
end

Instance Method Details

#error?Boolean

Returns true if the result is an exception.

Returns:

  • (Boolean)

    true if the result is an exception



30
31
32
# File 'lib/fluxo/result.rb', line 30

def error?
  type == :exception
end

#failure?Boolean

Returns true if the result is a failure.

Returns:

  • (Boolean)

    true if the result is a failure



25
26
27
# File 'lib/fluxo/result.rb', line 25

def failure?
  type == :failure
end

#on_error(handler_id = nil) ⇒ Object



42
43
44
# File 'lib/fluxo/result.rb', line 42

def on_error(handler_id = nil)
  tap { yield(self) if error? && (handler_id.nil? || ids.include?(handler_id)) }
end

#on_failure(handler_id = nil) ⇒ Object



38
39
40
# File 'lib/fluxo/result.rb', line 38

def on_failure(handler_id = nil)
  tap { yield(self) if failure? && (handler_id.nil? || ids.include?(handler_id)) }
end

#on_success(handler_id = nil) ⇒ Object



34
35
36
# File 'lib/fluxo/result.rb', line 34

def on_success(handler_id = nil)
  tap { yield(self) if success? && (handler_id.nil? || ids.include?(handler_id)) }
end

#success?Boolean

Returns true if the result is a success.

Returns:

  • (Boolean)

    true if the result is a success



20
21
22
# File 'lib/fluxo/result.rb', line 20

def success?
  type == :ok
end