Class: Safrano::Contract::Valid

Inherits:
Object
  • Object
show all
Defined in:
lib/safrano/contract.rb

Overview

represents a valid result. All tap_valid* handlers are executed

tap_error* handlers are not executed

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result) ⇒ Valid

Returns a new instance of Valid.



67
68
69
# File 'lib/safrano/contract.rb', line 67

def initialize(result)
  @result = result
end

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



65
66
67
# File 'lib/safrano/contract.rb', line 65

def result
  @result
end

Instance Method Details

#collect_result!Object



97
98
99
100
# File 'lib/safrano/contract.rb', line 97

def collect_result!
  @result = yield(*@result)
  self # allow chaining
end

#errorObject



102
103
104
# File 'lib/safrano/contract.rb', line 102

def error
  nil
end

#if_errorObject



84
85
86
# File 'lib/safrano/contract.rb', line 84

def if_error
  self # allow chaining
end

#if_valid {|@result| ... } ⇒ Object

Yields:



80
81
82
# File 'lib/safrano/contract.rb', line 80

def if_valid
  yield @result ## return this
end

#if_valid_collect {|@result| ... } ⇒ Object

Yields:



88
89
90
# File 'lib/safrano/contract.rb', line 88

def if_valid_collect
  yield(*@result) ## return this
end

#map_result!Object



92
93
94
95
# File 'lib/safrano/contract.rb', line 92

def map_result!
  @result = yield @result
  self # allow chaining
end

#tap_errorObject



71
72
73
# File 'lib/safrano/contract.rb', line 71

def tap_error
  self # allow chaining
end

#tap_valid {|@result| ... } ⇒ Object

Yields:



75
76
77
78
# File 'lib/safrano/contract.rb', line 75

def tap_valid
  yield @result
  self # allow chaining
end