Class: Anoubis::ApplicationController

Inherits:
ActionController::API
  • Object
show all
Includes:
ActionController::Cookies
Defined in:
app/controllers/anoubis/application_controller.rb

Overview

Main application controller class inherited from ActionController::API

Direct Known Subclasses

DataController

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#exportsAnubis::Export

Returns Export data class.

Returns:

  • (Anubis::Export)

    Export data class



19
20
21
# File 'app/controllers/anoubis/application_controller.rb', line 19

def exports
  @exports
end

#localeObject

Current used locale



11
12
13
# File 'app/controllers/anoubis/application_controller.rb', line 11

def locale
  @locale
end

#outputAnoubis::Output

Returns standard output.

Returns:



15
16
17
# File 'app/controllers/anoubis/application_controller.rb', line 15

def output
  @output
end

#redisClass

Returns Redis database class

Returns:

  • (Class)

    Redis class reference



8
9
10
# File 'app/controllers/anoubis/application_controller.rb', line 8

def redis
  @redis
end

#redis_prefixString

Returns Redis prefix for storing cache data. Prefix can be set in Rails.configuration.anoubis_redis_prefix configuration parameter.

Returns:

  • (String)

    Redis prefix



29
30
31
# File 'app/controllers/anoubis/application_controller.rb', line 29

def redis_prefix
  @redis_prefix
end

Instance Method Details

#after_anoubis_initializationObject

Procedure fires after initializes all parameters



73
74
75
# File 'app/controllers/anoubis/application_controller.rb', line 73

def after_anoubis_initialization

end

#check_originBoolean

Check current origin of header. By default origin always valid

Returns:

  • (Boolean)

    request host origin validation



96
97
98
# File 'app/controllers/anoubis/application_controller.rb', line 96

def check_origin
  true
end

#default_localeString

Returns default locale initialized in application configuration file. Variable is taken from Rails.configuration.i18n.default_locale parameter

Returns:

  • (String)

    default locale



24
25
26
# File 'app/controllers/anoubis/application_controller.rb', line 24

def default_locale
  Rails.configuration.i18n.default_locale.to_s
end

#options(methods = 'POST') ⇒ Object

Generates options headers for CORS requests

Parameters:

  • methods (String) (defaults to: 'POST')

    list of allowed HTTP actions separated by space (e.g. ‘GET POST DELETE’)



80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/controllers/anoubis/application_controller.rb', line 80

def options(methods = 'POST')
  return unless check_origin
  return unless request.origin

  headers['Access-Control-Allow-Origin'] = request.headers['origin']
  headers['Access-Control-Allow-Methods'] = methods

  return if request.method != 'OPTIONS'

  headers['Access-Control-Max-Age'] = '1000'
  headers['Access-Control-Allow-Headers'] = '*,x-requested-with,Content-Type,Authorization'
end

#pba_anoubis_applicationObject

Procedure fires before any action and setup default variables.



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/anoubis/application_controller.rb', line 57

def pba_anoubis_application
  self.locale = params[:locale] if params.has_key? :locale
  self.locale = default_locale unless self.locale
  self.locale = default_locale if self.locale == ''
  self.exports = nil
  begin
    I18n.locale = locale
  rescue
    I18n.locale = default_locale
  end

  after_anoubis_initialization
end