Class: Tzispa::Api::Handler
- Inherits:
-
Object
- Object
- Tzispa::Api::Handler
- Extended by:
- Forwardable
- Defined in:
- lib/tzispa/api/handler.rb
Constant Summary collapse
- HANDLED_UNDEFINED =
nil- HANDLED_OK =
1- HANDLED_MISSING_PARAMETER =
98- HANDLED_ERROR =
99- HANDLED_RESULT =
200- HANDLED_MESSAGES =
{ HANDLED_OK => 'La operación se ha realizado correctamente', HANDLED_MISSING_PARAMETER => 'Error: faltan parámetros para realizar la operación', HANDLED_ERROR => 'Error indeterminado: la operación no se ha podido realizar' }
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#response_verb ⇒ Object
readonly
Returns the value of attribute response_verb.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#initialize(context) ⇒ Handler
constructor
A new instance of Handler.
- #message ⇒ Object
- #result(response_verb:, status: HANDLED_UNDEFINED, data: nil, detailed_error: nil) ⇒ Object
Constructor Details
#initialize(context) ⇒ Handler
Returns a new instance of Handler.
26 27 28 |
# File 'lib/tzispa/api/handler.rb', line 26 def initialize(context) @context = context end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
12 13 14 |
# File 'lib/tzispa/api/handler.rb', line 12 def context @context end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
12 13 14 |
# File 'lib/tzispa/api/handler.rb', line 12 def data @data end |
#response_verb ⇒ Object (readonly)
Returns the value of attribute response_verb.
12 13 14 |
# File 'lib/tzispa/api/handler.rb', line 12 def response_verb @response_verb end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
12 13 14 |
# File 'lib/tzispa/api/handler.rb', line 12 def status @status end |
Instance Method Details
#message ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/tzispa/api/handler.rb', line 37 def if @status.nil? nil elsif @status >= HANDLED_OK && @status <= HANDLED_ERROR HANDLED_MESSAGES[@status] elsif @status > HANDLED_ERROR && @status < HANDLED_RESULT @status elsif @status > HANDLED_RESULT @status else nil end end |
#result(response_verb:, status: HANDLED_UNDEFINED, data: nil, detailed_error: nil) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/tzispa/api/handler.rb', line 30 def result(response_verb:, status: HANDLED_UNDEFINED, data: nil, detailed_error: nil) @status = status @response_verb = response_verb @data = data @detailed_error = detailed_error end |