Class: TxAsr::ServiceResult
- Inherits:
-
Object
- Object
- TxAsr::ServiceResult
- Defined in:
- lib/tx_asr/service_result.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#message ⇒ Object
Returns the value of attribute message.
-
#message_type ⇒ Object
Returns the value of attribute message_type.
-
#success ⇒ Object
(also: #success?)
Returns the value of attribute success.
Instance Method Summary collapse
- #failure? ⇒ Boolean
- #get_message_type ⇒ Object
-
#initialize(success: false, errors: nil, message: nil, message_type: nil, data: nil) ⇒ ServiceResult
constructor
A new instance of ServiceResult.
- #on_failure {|_self| ... } ⇒ Object
- #on_success {|_self| ... } ⇒ Object
Constructor Details
#initialize(success: false, errors: nil, message: nil, message_type: nil, data: nil) ⇒ ServiceResult
Returns a new instance of ServiceResult.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/tx_asr/service_result.rb', line 9 def initialize(success: false, errors: nil, message: nil, message_type: nil, data: nil) self.success = success self.data = data self.errors = errors.is_a?(Array) ? errors : [errors] self. = self. = end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
3 4 5 |
# File 'lib/tx_asr/service_result.rb', line 3 def data @data end |
#errors ⇒ Object
Returns the value of attribute errors.
3 4 5 |
# File 'lib/tx_asr/service_result.rb', line 3 def errors @errors end |
#message ⇒ Object
Returns the value of attribute message.
3 4 5 |
# File 'lib/tx_asr/service_result.rb', line 3 def @message end |
#message_type ⇒ Object
Returns the value of attribute message_type.
3 4 5 |
# File 'lib/tx_asr/service_result.rb', line 3 def @message_type end |
#success ⇒ Object Also known as: success?
Returns the value of attribute success.
3 4 5 |
# File 'lib/tx_asr/service_result.rb', line 3 def success @success end |
Instance Method Details
#failure? ⇒ Boolean
23 24 25 |
# File 'lib/tx_asr/service_result.rb', line 23 def failure? !success? end |
#get_message_type ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/tx_asr/service_result.rb', line 35 def if .present? .to_sym elsif success? :notice else :error end end |
#on_failure {|_self| ... } ⇒ Object
31 32 33 |
# File 'lib/tx_asr/service_result.rb', line 31 def on_failure yield(self) if failure? end |
#on_success {|_self| ... } ⇒ Object
27 28 29 |
# File 'lib/tx_asr/service_result.rb', line 27 def on_success yield(self) if success? end |