Class: Anetwork::Messages
- Inherits:
-
Object
- Object
- Anetwork::Messages
- Defined in:
- lib/Messages.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#code ⇒ Object
setter and getter varibules.
-
#config ⇒ Object
setter and getter varibules.
-
#error(code) ⇒ Object
The error message.
-
#error_code ⇒ Object
setter and getter varibules.
-
#headers ⇒ Object
setter and getter varibules.
-
#lang ⇒ Object
setter and getter varibules.
-
#text ⇒ Object
setter and getter varibules.
Instance Method Summary collapse
-
#connection_refused ⇒ Object
Database connection is refused.
-
#delete_faild(message = nil) ⇒ Object
Delete action is faild.
-
#delete_succeeded(message = nil) ⇒ Object
Delete action is succeed.
-
#initialize(lang = 'en') ⇒ Object
constructor
initialize method.
-
#insert_faild(message = nil) ⇒ Object
Insert action is faild.
-
#insert_succeeded(message = nil) ⇒ Object
Insert action is succeed.
-
#method_not_allowed ⇒ Object
Method is not allowed.
-
#not_found ⇒ Object
Page requested is not found.
-
#request_field_duplicated ⇒ Object
The request field is duplicated.
-
#request_field_notfound ⇒ Object
The request field is not found.
-
#succeed(data) ⇒ Object
Request succeeded and contains json result.
-
#update_faild(message = nil) ⇒ Object
Update action is succeed.
-
#update_succeeded(message = nil) ⇒ Object
Update action is succeed.
-
#validation_errors(message = nil) ⇒ Object
There ara validation errors.
-
#wrong_parameters ⇒ Object
Wrong parameters are entered.
Constructor Details
#initialize(lang = 'en') ⇒ Object
initialize method
15 16 17 18 19 20 21 22 23 |
# File 'lib/Messages.rb', line 15 def initialize(lang = 'en') @lang = I18n.locale if @lang != '' || @lang != nil lang = @lang end @config = eval(File.open(__dir__ + "/errors/#{lang}.rb").read) end |
Instance Attribute Details
#code ⇒ Object
setter and getter varibules
6 7 8 |
# File 'lib/Messages.rb', line 6 def code @code end |
#config ⇒ Object
setter and getter varibules
6 7 8 |
# File 'lib/Messages.rb', line 6 def config @config end |
#error(code) ⇒ Object
The error message
6 7 8 |
# File 'lib/Messages.rb', line 6 def error @error end |
#error_code ⇒ Object
setter and getter varibules
6 7 8 |
# File 'lib/Messages.rb', line 6 def error_code @error_code end |
#headers ⇒ Object
setter and getter varibules
6 7 8 |
# File 'lib/Messages.rb', line 6 def headers @headers end |
#lang ⇒ Object
setter and getter varibules
6 7 8 |
# File 'lib/Messages.rb', line 6 def lang @lang end |
#text ⇒ Object
setter and getter varibules
6 7 8 |
# File 'lib/Messages.rb', line 6 def text @text end |
Instance Method Details
#connection_refused ⇒ Object
Database connection is refused
149 150 151 152 153 154 |
# File 'lib/Messages.rb', line 149 def connection_refused self.set_status_code(445) .set_status_text('fail') .set_error_code(5445) . end |
#delete_faild(message = nil) ⇒ Object
Delete action is faild
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/Messages.rb', line 96 def delete_faild( = nil) if == nil = @config[:fail][:delete] end self.set_status_code(447) .set_status_text('fail') .set_error_code(5447) .() end |
#delete_succeeded(message = nil) ⇒ Object
Delete action is succeed
45 46 47 48 49 50 51 52 53 |
# File 'lib/Messages.rb', line 45 def delete_succeeded( = nil) if == nil = @config[:success][:delete] end self.set_status_code(200) .set_status_text('success') .() end |
#insert_faild(message = nil) ⇒ Object
Insert action is faild
132 133 134 135 136 137 138 139 140 141 |
# File 'lib/Messages.rb', line 132 def insert_faild( = nil) if == nil = @config[:fail][:insert] end self.set_status_code(448) .set_status_text('fail') .set_error_code(5448) .() end |
#insert_succeeded(message = nil) ⇒ Object
Insert action is succeed
79 80 81 82 83 84 85 86 87 |
# File 'lib/Messages.rb', line 79 def insert_succeeded( = nil) if == nil = @config[:success][:insert] end self.set_status_code(200) .set_status_text('success') .() end |
#method_not_allowed ⇒ Object
Method is not allowed
188 189 190 191 192 193 |
# File 'lib/Messages.rb', line 188 def method_not_allowed self.set_status_code(405) .set_status_text('fail') .set_error_code(5405) . end |
#not_found ⇒ Object
Page requested is not found
162 163 164 165 166 167 |
# File 'lib/Messages.rb', line 162 def not_found self.set_status_code(404) .set_status_text('fail') .set_error_code(5404) . end |
#request_field_duplicated ⇒ Object
The request field is duplicated
227 228 229 230 231 232 |
# File 'lib/Messages.rb', line 227 def request_field_duplicated self.set_status_code(400) .set_status_text('fail') .set_error_code(1004) . end |
#request_field_notfound ⇒ Object
The request field is not found
214 215 216 217 218 219 |
# File 'lib/Messages.rb', line 214 def request_field_notfound self.set_status_code(446) .set_status_text('fail') .set_error_code(1001) . end |
#succeed(data) ⇒ Object
Request succeeded and contains json result
32 33 34 35 36 |
# File 'lib/Messages.rb', line 32 def succeed(data) self.set_status_code(200) .set_status_text('success') .respond_with_result(data) end |
#update_faild(message = nil) ⇒ Object
Update action is succeed
114 115 116 117 118 119 120 121 122 123 |
# File 'lib/Messages.rb', line 114 def update_faild( = nil) if == nil = @config[:fail][:update] end self.set_status_code(449) .set_status_text('fail') .set_error_code(5449) .() end |
#update_succeeded(message = nil) ⇒ Object
Update action is succeed
62 63 64 65 66 67 68 69 70 |
# File 'lib/Messages.rb', line 62 def update_succeeded( = nil) if == nil = @config[:success][:update] end self.set_status_code(200) .set_status_text('success') .() end |
#validation_errors(message = nil) ⇒ Object
There ara validation errors
201 202 203 204 205 206 |
# File 'lib/Messages.rb', line 201 def validation_errors( = nil) self.set_status_code(420) .set_status_text('fail') .set_error_code(5420) .() end |
#wrong_parameters ⇒ Object
Wrong parameters are entered
175 176 177 178 179 180 |
# File 'lib/Messages.rb', line 175 def wrong_parameters self.set_status_code(406) .set_status_text('fail') .set_error_code(5406) . end |