Module: Quiver::Result
- Included in:
- Adapter::AdapterResult, Mapper::MapperResult
- Defined in:
- lib/quiver/result.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #initialize(object = nil, errors = nil, data = {}) ⇒ Object
- #success? ⇒ Boolean
- #when(success: nil, failure: nil) ⇒ Object
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
3 4 5 |
# File 'lib/quiver/result.rb', line 3 def data @data end |
#errors ⇒ Object
Returns the value of attribute errors.
3 4 5 |
# File 'lib/quiver/result.rb', line 3 def errors @errors end |
#object ⇒ Object
Returns the value of attribute object.
3 4 5 |
# File 'lib/quiver/result.rb', line 3 def object @object end |
Instance Method Details
#==(other) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/quiver/result.rb', line 33 def ==(other) other.is_a?(Result) && object == other.object && errors == other.errors && data == other.data end |
#initialize(object = nil, errors = nil, data = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/quiver/result.rb', line 5 def initialize(object=nil, errors=nil, data={}) errors ||= Quiver::ErrorCollection.new if block_given? object = yield errors end self.object = object self.errors = errors self.data = data end |
#success? ⇒ Boolean
17 18 19 |
# File 'lib/quiver/result.rb', line 17 def success? errors.success? end |
#when(success: nil, failure: nil) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/quiver/result.rb', line 21 def when(success: nil, failure: nil) # one day if we ever have Ruby 2.1 we can delete this raise ArgumentError, 'missing keyword: success' if success == nil raise ArgumentError, 'missing keyword: failure' if failure == nil if success? success.call(object, self) else failure.call(errors, self) end end |