Class: Pathway::Result

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/pathway/result.rb

Direct Known Subclasses

Failure, Success

Defined Under Namespace

Modules: Mixin Classes: Failure, Success

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



6
7
8
# File 'lib/pathway/result.rb', line 6

def error
  @error
end

#valueObject (readonly)

Returns the value of attribute value.



6
7
8
# File 'lib/pathway/result.rb', line 6

def value
  @value
end

Class Method Details

.failure(error) ⇒ Object



78
79
80
# File 'lib/pathway/result.rb', line 78

def self.failure(error)
  Failure.new(error)
end

.result(object) ⇒ Object



82
83
84
# File 'lib/pathway/result.rb', line 82

def self.result(object)
  object.is_a?(Result) ? object : success(object)
end

.success(value) ⇒ Object



74
75
76
# File 'lib/pathway/result.rb', line 74

def self.success(value)
  Success.new(value)
end

Instance Method Details

#deconstructObject



58
59
60
# File 'lib/pathway/result.rb', line 58

def deconstruct
  [value_for_deconstruct]
end

#deconstruct_keys(keys) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/pathway/result.rb', line 62

def deconstruct_keys(keys)
  if value_for_deconstruct.respond_to?(:deconstruct_keys)
    value_for_deconstruct.deconstruct_keys(keys)
  else
    {}
  end
end

#failure?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/pathway/result.rb', line 70

def failure?
  !success?
end