Class: Anoubis::Output::Basic
- Inherits:
-
Object
- Object
- Anoubis::Output::Basic
- Defined in:
- app/controllers/anoubis/output/basic.rb
Overview
Output subclass that represents parametrs for basic requests
Instance Attribute Summary collapse
-
#messages ⇒ Hash<string>
Hash of messages.
-
#result ⇒ Number
Controller action output result code.
-
#tab ⇒ String
Current returned tab.
-
#title ⇒ string
The page title of current loaded frame.
Instance Method Summary collapse
-
#hash_to_json(hash) ⇒ Array
Convert hash to array json output.
-
#initialize ⇒ Basic
constructor
Output class initialization.
-
#message ⇒ String
Generates output message based on result variable.
-
#options_to_json(options) ⇒ Hash<Array>
Convert options hash to array json output.
-
#to_h ⇒ Hash
Generates hash representation of output class.
Constructor Details
#initialize ⇒ Basic
Output class initialization. Sets default class parameters.
28 29 30 31 32 33 34 35 36 37 |
# File 'app/controllers/anoubis/output/basic.rb', line 28 def initialize self.title = nil self.result = 0 self.tab = '' self. = { '0': I18n.t('anoubis.success'), '-1': I18n.t('errors.access_not_allowed'), '-2': I18n.t('errors.incorrect_parameters') } end |
Instance Attribute Details
#messages ⇒ Hash<string>
Returns hash of messages.
15 |
# File 'app/controllers/anoubis/output/basic.rb', line 15 class_attribute :messages |
#result ⇒ Number
Zero value means successful. Negative value means error.
Returns controller action output result code.
20 |
# File 'app/controllers/anoubis/output/basic.rb', line 20 class_attribute :result, default: 0 |
#tab ⇒ String
Returns current returned tab.
24 |
# File 'app/controllers/anoubis/output/basic.rb', line 24 class_attribute :tab, default: '' |
#title ⇒ string
Returns the page title of current loaded frame.
11 |
# File 'app/controllers/anoubis/output/basic.rb', line 11 class_attribute :title |
Instance Method Details
#hash_to_json(hash) ⇒ Array
Convert hash to array json output
65 66 67 68 69 70 71 |
# File 'app/controllers/anoubis/output/basic.rb', line 65 def hash_to_json(hash) result = [] hash.each_key do |key| result.push({ key: key.to_s, value: hash[key] }) end result end |
#message ⇒ String
Generates output message based on result variable.
56 57 58 59 |
# File 'app/controllers/anoubis/output/basic.rb', line 56 def return [result.to_s.to_sym] if .key? result.to_s.to_sym I18n.t('errors.internal_error') end |
#options_to_json(options) ⇒ Hash<Array>
Convert options hash to array json output
77 78 79 80 81 82 83 |
# File 'app/controllers/anoubis/output/basic.rb', line 77 def () result = {} .each_key do |key| result[key] = self.hash_to_json([key]) end result end |
#to_h ⇒ Hash
Generates hash representation of output class
42 43 44 45 46 47 48 49 50 51 |
# File 'app/controllers/anoubis/output/basic.rb', line 42 def to_h result = { result: self.result, timestamp: Time.now.to_i, message: } result[:title] = self.title if self.title result[:tab] = self.tab if self.tab != '' result end |