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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#localeObject

Current used locale



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

def locale
  @locale
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



21
22
23
# File 'app/controllers/anoubis/application_controller.rb', line 21

def redis_prefix
  @redis_prefix
end

Instance Method Details

#check_originBoolean

Check current origin of header. By default origin always valid

Returns:

  • (Boolean)

    request host origin validation



75
76
77
# File 'app/controllers/anoubis/application_controller.rb', line 75

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



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

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')



63
64
65
66
67
68
69
70
# File 'app/controllers/anoubis/application_controller.rb', line 63

def options(methods = 'POST')
  if check_origin
    headers['Access-Control-Allow-Origin'] = request.headers['origin']
    headers['Access-Control-Allow-Methods'] = methods
    headers['Access-Control-Max-Age'] = '1000'
    headers['Access-Control-Allow-Headers'] = '*,x-requested-with,Content-Type,Authorization'
  end
end

#pba_anoubis_applicationObject

Procedure fires before any action and setup default variables.



49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/anoubis/application_controller.rb', line 49

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 == ''
  begin
    I18n.locale = locale
  rescue
    I18n.locale = default_locale
  end
end