Class: Results::Good
- Inherits:
-
Struct
- Object
- Struct
- Results::Good
- Defined in:
- lib/results.rb
Instance Attribute Summary collapse
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #and ⇒ Object
- #flat_map {|value| ... } ⇒ Object (also: #validate)
- #map ⇒ Object
- #validate_all(*validations) ⇒ Object
- #when(msg_or_proc_or_filter) ⇒ Object
- #when_all(*filters) ⇒ Object
- #when_all_not(*filters) ⇒ Object
- #when_not(msg_or_proc_or_filter) ⇒ Object
- #zip(other) ⇒ Object
Instance Attribute Details
#value ⇒ Object
Returns the value of attribute value
85 86 87 |
# File 'lib/results.rb', line 85 def value @value end |
Instance Method Details
#and ⇒ Object
110 111 112 |
# File 'lib/results.rb', line 110 def and self end |
#flat_map {|value| ... } ⇒ Object Also known as: validate
90 91 92 |
# File 'lib/results.rb', line 90 def flat_map yield(value) end |
#map ⇒ Object
86 87 88 |
# File 'lib/results.rb', line 86 def map flat_map { |v| Good.new(yield v) } end |
#validate_all(*validations) ⇒ Object
122 123 124 |
# File 'lib/results.rb', line 122 def validate_all(*validations) validations.flatten.inject(self) { |prev_result, validation| prev_result.and.validate(&validation) } end |
#when(msg_or_proc_or_filter) ⇒ Object
96 97 98 99 100 101 |
# File 'lib/results.rb', line 96 def when(msg_or_proc_or_filter) validate do |v| predicate, msg_or_proc = (msg_or_proc_or_filter, v) { yield v } predicate ? self : Bad.new(Results.call_or_yield_or_return(msg_or_proc, v) { |msg| 'not ' + msg }, v) end end |
#when_all(*filters) ⇒ Object
114 115 116 |
# File 'lib/results.rb', line 114 def when_all(*filters) filters.flatten.inject(self) { |prev_result, filter| prev_result.and.when(filter) } end |
#when_all_not(*filters) ⇒ Object
118 119 120 |
# File 'lib/results.rb', line 118 def when_all_not(*filters) filters.flatten.inject(self) { |prev_result, filter| prev_result.and.when_not(filter) } end |
#when_not(msg_or_proc_or_filter) ⇒ Object
103 104 105 106 107 108 |
# File 'lib/results.rb', line 103 def when_not(msg_or_proc_or_filter) validate do |v| predicate, msg_or_proc = (msg_or_proc_or_filter, v) { yield v } !predicate ? self : Bad.new(Results.call_or_yield_or_return(msg_or_proc, v), v) end end |