Class: Reply
- Inherits:
-
Object
- Object
- Reply
- Defined in:
- lib/reply/reply.rb
Constant Summary collapse
- SIMPLE_STATUS_ERROR =
0- SIMPLE_STATUS_SUCCESS =
1- SIMPLE_STATUS_WARNING =
2- SIMPLE_STATUSES =
[SIMPLE_STATUS_SUCCESS, SIMPLE_STATUS_WARNING, SIMPLE_STATUS_ERROR]
Instance Attribute Summary collapse
-
#data ⇒ Object
simple_status either 0, 1, 2 status can be any code e.g.
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
-
#simple_status ⇒ Object
Returns the value of attribute simple_status.
-
#status ⇒ Object
simple_status either 0, 1, 2 status can be any code e.g.
Instance Method Summary collapse
- #add_errors(array_or_str) ⇒ Object (also: #add_error)
- #add_messages(array_or_str) ⇒ Object (also: #add_message)
-
#clear_messages ⇒ Object
————————————————————————-.
- #error? ⇒ Boolean (also: #failure?)
-
#initialize(params = {}) ⇒ Reply
constructor
A new instance of Reply.
- #mark_as_error ⇒ Object (also: #error!)
- #mark_as_success ⇒ Object (also: #success!)
- #mark_as_warning ⇒ Object (also: #warning!)
- #replace_messages(array_or_str) ⇒ Object
- #replace_messages_with_errors_for(object) ⇒ Object
-
#success? ⇒ Boolean
(also: #successful?)
————————————————————————- Predicates ————————————————————————-.
- #warning? ⇒ Boolean
Constructor Details
#initialize(params = {}) ⇒ Reply
Returns a new instance of Reply.
12 13 14 15 16 17 |
# File 'lib/reply/reply.rb', line 12 def initialize(params={}) @messages = params[:messages] || [] @data = params[:data] || {} @status = params[:status] || nil @simple_status = params[:simple_status] || SIMPLE_STATUS_SUCCESS end |
Instance Attribute Details
#data ⇒ Object
simple_status either 0, 1, 2 status can be any code e.g. 200, 401
4 5 6 |
# File 'lib/reply/reply.rb', line 4 def data @data end |
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
5 6 7 |
# File 'lib/reply/reply.rb', line 5 def @messages end |
#simple_status ⇒ Object
Returns the value of attribute simple_status.
5 6 7 |
# File 'lib/reply/reply.rb', line 5 def simple_status @simple_status end |
#status ⇒ Object
simple_status either 0, 1, 2 status can be any code e.g. 200, 401
4 5 6 |
# File 'lib/reply/reply.rb', line 4 def status @status end |
Instance Method Details
#add_errors(array_or_str) ⇒ Object Also known as: add_error
47 48 49 50 |
# File 'lib/reply/reply.rb', line 47 def add_errors(array_or_str) (array_or_str) mark_as_error end |
#add_messages(array_or_str) ⇒ Object Also known as: add_message
32 33 34 35 |
# File 'lib/reply/reply.rb', line 32 def (array_or_str) array = wrap_arr(array_or_str) @messages = @messages | array end |
#clear_messages ⇒ Object
28 29 30 |
# File 'lib/reply/reply.rb', line 28 def @messages.clear end |
#error? ⇒ Boolean Also known as: failure?
77 78 79 |
# File 'lib/reply/reply.rb', line 77 def error? @simple_status == SIMPLE_STATUS_ERROR end |
#mark_as_error ⇒ Object Also known as: error!
58 59 60 |
# File 'lib/reply/reply.rb', line 58 def mark_as_error @simple_status = SIMPLE_STATUS_ERROR end |
#mark_as_success ⇒ Object Also known as: success!
53 54 55 |
# File 'lib/reply/reply.rb', line 53 def mark_as_success @simple_status = SIMPLE_STATUS_SUCCESS end |
#mark_as_warning ⇒ Object Also known as: warning!
63 64 65 |
# File 'lib/reply/reply.rb', line 63 def mark_as_warning @simple_status = SIMPLE_STATUS_WARNING end |
#replace_messages(array_or_str) ⇒ Object
38 39 40 41 |
# File 'lib/reply/reply.rb', line 38 def (array_or_str) array = wrap_arr(array_or_str) @messages = array end |
#replace_messages_with_errors_for(object) ⇒ Object
43 44 45 |
# File 'lib/reply/reply.rb', line 43 def (object) @messages = object.errors. end |
#success? ⇒ Boolean Also known as: successful?
Predicates
72 73 74 |
# File 'lib/reply/reply.rb', line 72 def success? @simple_status == SIMPLE_STATUS_SUCCESS end |
#warning? ⇒ Boolean
82 83 84 |
# File 'lib/reply/reply.rb', line 82 def warning? @simple_status == SIMPLE_STATUS_WARNING end |