Class: MiniProgram::ServiceResult
- Inherits:
-
Object
- Object
- MiniProgram::ServiceResult
- Defined in:
- lib/mini_program/service_result.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#error ⇒ Object
Returns the value of attribute error.
-
#message ⇒ Object
Returns the value of attribute message.
-
#message_kind ⇒ Object
Returns the value of attribute message_kind.
-
#message_type ⇒ Object
Returns the value of attribute message_type.
-
#success ⇒ Object
(also: #success?)
Returns the value of attribute success.
Instance Method Summary collapse
- #as_json(options = nil) ⇒ Object
- #failure? ⇒ Boolean
- #get_message_type ⇒ Object
-
#initialize(success: false, error: nil, message: nil, message_type: nil, message_kind: nil, data: {}) ⇒ ServiceResult
constructor
A new instance of ServiceResult.
- #on_failure {|_self| ... } ⇒ Object
- #on_success {|_self| ... } ⇒ Object
Constructor Details
#initialize(success: false, error: nil, message: nil, message_type: nil, message_kind: nil, data: {}) ⇒ ServiceResult
Returns a new instance of ServiceResult.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/mini_program/service_result.rb', line 12 def initialize(success: false, error: nil, message: nil, message_type: nil, message_kind: nil, data: {}) self.success = success self.data = (data.presence || {}).with_indifferent_access self.error = error self. = self. = self. = end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
3 4 5 |
# File 'lib/mini_program/service_result.rb', line 3 def data @data end |
#error ⇒ Object
Returns the value of attribute error.
3 4 5 |
# File 'lib/mini_program/service_result.rb', line 3 def error @error end |
#message ⇒ Object
Returns the value of attribute message.
3 4 5 |
# File 'lib/mini_program/service_result.rb', line 3 def @message end |
#message_kind ⇒ Object
Returns the value of attribute message_kind.
3 4 5 |
# File 'lib/mini_program/service_result.rb', line 3 def @message_kind end |
#message_type ⇒ Object
Returns the value of attribute message_type.
3 4 5 |
# File 'lib/mini_program/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/mini_program/service_result.rb', line 3 def success @success end |
Instance Method Details
#as_json(options = nil) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/mini_program/service_result.rb', line 53 def as_json( = nil) { success: , data: , message:, message_type: , message_kind:, error:, } end |
#failure? ⇒ Boolean
29 30 31 |
# File 'lib/mini_program/service_result.rb', line 29 def failure? !success? end |
#get_message_type ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/mini_program/service_result.rb', line 43 def if .present? .to_sym elsif success? :notice else :error end end |
#on_failure {|_self| ... } ⇒ Object
38 39 40 41 |
# File 'lib/mini_program/service_result.rb', line 38 def on_failure yield(self) if failure? self end |
#on_success {|_self| ... } ⇒ Object
33 34 35 36 |
# File 'lib/mini_program/service_result.rb', line 33 def on_success yield(self) if success? self end |