Class: Tpt::Rails::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/tpt/rails/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

:nodoc:



46
47
48
# File 'lib/tpt/rails/config.rb', line 46

def initialize # :nodoc:
  @health_checks = Tpt::Rails::Internal::HealthChecks.new
end

Instance Attribute Details

#app_envObject

E.g. production/integration/jordan123



11
12
13
# File 'lib/tpt/rails/config.rb', line 11

def app_env
  @app_env
end

#app_nameObject

E.g. earnings/resource-write/tpt-data



13
14
15
# File 'lib/tpt/rails/config.rb', line 13

def app_name
  @app_name
end

#bugsnag_api_keyObject

A project-specific api key from Bugsnag



15
16
17
# File 'lib/tpt/rails/config.rb', line 15

def bugsnag_api_key
  @bugsnag_api_key
end

#datadog_statsd_urlObject

Set this in the form of: statsd://:[port]‘



17
18
19
# File 'lib/tpt/rails/config.rb', line 17

def datadog_statsd_url
  @datadog_statsd_url
end

#datadog_trace_urlObject

Set this in the form of: datadog://:[port]‘



19
20
21
# File 'lib/tpt/rails/config.rb', line 19

def datadog_trace_url
  @datadog_trace_url
end

#health_checksObject (readonly)

Internal code



44
45
46
# File 'lib/tpt/rails/config.rb', line 44

def health_checks
  @health_checks
end

#redis_urlObject

Set this in the form of: redis://:@[hostname]:/[db]



21
22
23
# File 'lib/tpt/rails/config.rb', line 21

def redis_url
  @redis_url
end

#rollbar_access_tokenObject

A project-specific access token from rollbar



23
24
25
# File 'lib/tpt/rails/config.rb', line 23

def rollbar_access_token
  @rollbar_access_token
end

#rollbar_enabledObject

Allow enabling/disabling Rollbar. Defaults to false.



25
26
27
# File 'lib/tpt/rails/config.rb', line 25

def rollbar_enabled
  @rollbar_enabled
end

Instance Method Details

#health_check(name, &block) ⇒ Object

Add a health check to the endpoint provided at ‘/internal/health-check` by Tpt::Rails::HealthChecksController.

The block provided to this method should return a truthy/falsey value for success/failure.

Example:

config.health_check(:foo) { 'foo' == 'foo' }


36
37
38
# File 'lib/tpt/rails/config.rb', line 36

def health_check(name, &block)
  @health_checks.add(name, &block)
end

#report(error) ⇒ Object

:nodoc:



77
78
79
# File 'lib/tpt/rails/config.rb', line 77

def report(error) # :nodoc:
  @error_reporter.report(error)
end

#setupObject

:nodoc:



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/tpt/rails/config.rb', line 50

def setup # :nodoc:
  if redis_url
    # Ensure that redis has been added to the app's Gemfile if a `redis_url` has been set
    gem 'redis', '>= 4', '< 5'
    gem 'hiredis'

    Redis.current = Redis.new(url: redis_url, driver: :hiredis)
  end

  @datadog = Tpt::Rails::Internal::Datadog.new(
    statsd_url: datadog_statsd_url,
    trace_url: datadog_trace_url,
  )

  @health_checks.setup

  @error_reporter = Tpt::Rails::Internal::ErrorReporter.new(
    bugsnag_api_key: bugsnag_api_key.presence,
    rollbar_access_token: rollbar_access_token.presence,
    rollbar_enabled: rollbar_enabled ? true : false,
  )
end

#statsdObject

:nodoc:



73
74
75
# File 'lib/tpt/rails/config.rb', line 73

def statsd # :nodoc:
  @datadog.statsd
end