Class: OpenteamCommons::Engine

Inherits:
Rails::Engine
  • Object
show all
Defined in:
lib/openteam-commons/engine.rb

Instance Method Summary collapse

Instance Method Details

#read_settingsObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/openteam-commons/engine.rb', line 18

def read_settings
  Settings.read(Rails.root.join('config', 'settings.yml')) if Rails.root.join('config', 'settings.yml').exist?

  Settings.defaults Settings.extract!(Rails.env)[Rails.env] || {}
  Settings.extract!(:test, :development, :production)

  Settings.define 'amqp.url',         env_var: 'AMQP_URL'

  Settings.define 'app.secret',       env_var: 'APP_SECRET'
  Settings.define 'app.url',          env_var: 'APP_URL'

  Settings.define 'errors.key',       env_var: 'ERRORS_KEY'
  Settings.define 'errors.url',       env_var: 'ERRORS_URL'

  Settings.define 'solr.url',         env_var: 'SOLR_URL'

  Settings.define 'sso.key',          env_var: 'SSO_KEY'
  Settings.define 'sso.secret',       env_var: 'SSO_SECRET'
  Settings.define 'sso.url',          env_var: 'SSO_URL'

  Settings.define 'storage.url',      env_var: 'STORAGE_URL'
end

#setup_airbrakeObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/openteam-commons/engine.rb', line 41

def setup_airbrake
  if Settings['errors.key'].present?
    if Airbrake::AIRBRAKE_VERSION.to_i < 4
      Airbrake.configure do |config|
        config.api_key = Settings['errors.key']

        URI.parse(Settings['errors.url']).tap do |url|
          config.host   = url.host
          config.port   = url.port
          config.secure = url.scheme.inquiry.https?
        end
      end
    else
      Airbrake.configure do |config|
        config.project_key = Settings['errors.key']
        config.project_id = 1
        config.host = Settings['errors.url']
        config.environment = Rails.env
        config.ignore_environments = %w[development test]
      end
      ignore_errors = [
        'ActionController::RoutingError',
        'ActiveRecord::RecordNotFound',
      ]
      Airbrake.add_filter do |notice|
        if notice[:errors].any? { |error| ignore_errors.include? error[:type] }
          notice.ignore!
        end
      end
    end
  end
end

#setup_localeObject



78
79
80
# File 'lib/openteam-commons/engine.rb', line 78

def setup_locale
  I18n.locale = I18n.default_locale
end

#setup_secretObject



74
75
76
# File 'lib/openteam-commons/engine.rb', line 74

def setup_secret
  Rails.application.config.secret_token = Settings['app.secret']
end