Class: Anoubis::Output::Basic

Inherits:
Object
  • Object
show all
Defined in:
app/controllers/anoubis/output/basic.rb

Overview

Output subclass that represents parametrs for basic requests

Direct Known Subclasses

Autocomplete, Data, Delete, Edit, Frame, Login, Menu, Update

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBasic

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.messages = {
      '0': I18n.t('anoubis.success'),
      '-1': I18n.t('errors.access_not_allowed'),
      '-2': I18n.t('errors.incorrect_parameters')
  }
end

Instance Attribute Details

#messagesHash<string>

Returns hash of messages.

Returns:

  • (Hash<string>)

    hash of messages



15
# File 'app/controllers/anoubis/output/basic.rb', line 15

class_attribute :messages

#resultNumber

Note:

Zero value means successful. Negative value means error.

Returns controller action output result code.

Returns:

  • (Number)

    controller action output result code.



20
# File 'app/controllers/anoubis/output/basic.rb', line 20

class_attribute :result, default: 0

#tabString

Returns current returned tab.

Returns:

  • (String)

    current returned tab



24
# File 'app/controllers/anoubis/output/basic.rb', line 24

class_attribute :tab, default: ''

#titlestring

Returns the page title of current loaded frame.

Returns:

  • (string)

    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

Parameters:

  • hash (Hash)

    hash representation

Returns:

  • (Array)

    array representation



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

#messageString

Generates output message based on result variable.

Returns:

  • (String)

    output message



56
57
58
59
# File 'app/controllers/anoubis/output/basic.rb', line 56

def message
  return messages[result.to_s.to_sym] if messages.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

Parameters:

  • options (Hash<Hash>)

    options with hash representation

Returns:

  • (Hash<Array>)

    options with array representation



77
78
79
80
81
82
83
# File 'app/controllers/anoubis/output/basic.rb', line 77

def options_to_json(options)
  result = {}
  options.each_key do |key|
    result[key] = self.hash_to_json(options[key])
  end
  result
end

#to_hHash

Generates hash representation of output class

Returns:

  • (Hash)

    hash representation of all class data



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: message
  }
  result[:title] = self.title if self.title
  result[:tab] = self.tab if self.tab != ''
  result
end