Class: LastResort::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/last-resort/config.rb

Overview

The configuration class is used to build up contact and scheduling information for Last Resort.

Instances of this class power the schedule.rb’s DSL. By default it will attempt to load in and evaluate a schedule.rb file upon construction, but it can also be manually configured.

Constant Summary collapse

DOT_ENV_PATH =
".env"
CONFIG_PATH =
"schedule.rb"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(skip_schedule_load = false) ⇒ Config

If skip_schedule_load is true, the config instance will not attempt to load schedule.rb. Useful for unit testing or programmatic configuration.



23
24
25
26
27
28
# File 'lib/last-resort/config.rb', line 23

def initialize skip_schedule_load = false
  @contacts = {}
  @matchers = []
  @schedules = []
  run_config_in_context unless skip_schedule_load
end

Instance Attribute Details

#contactsObject

The host provided to services for webhooks



13
14
15
# File 'lib/last-resort/config.rb', line 13

def contacts
  @contacts
end

#contextio_accountObject

The host provided to services for webhooks



13
14
15
# File 'lib/last-resort/config.rb', line 13

def 
  @contextio_account
end

#contextio_keyObject

The host provided to services for webhooks



13
14
15
# File 'lib/last-resort/config.rb', line 13

def contextio_key
  @contextio_key
end

#contextio_secretObject

The host provided to services for webhooks



13
14
15
# File 'lib/last-resort/config.rb', line 13

def contextio_secret
  @contextio_secret
end

#hostObject

The host provided to services for webhooks



13
14
15
# File 'lib/last-resort/config.rb', line 13

def host
  @host
end

#local_utc_offset_in_secondsObject

The host provided to services for webhooks



13
14
15
# File 'lib/last-resort/config.rb', line 13

def local_utc_offset_in_seconds
  @local_utc_offset_in_seconds
end

#matchersObject

The host provided to services for webhooks



13
14
15
# File 'lib/last-resort/config.rb', line 13

def matchers
  @matchers
end

#schedulesObject

The host provided to services for webhooks



13
14
15
# File 'lib/last-resort/config.rb', line 13

def schedules
  @schedules
end

#twilio_auth_tokenObject

The host provided to services for webhooks



13
14
15
# File 'lib/last-resort/config.rb', line 13

def twilio_auth_token
  @twilio_auth_token
end

#twilio_sidObject

The host provided to services for webhooks



13
14
15
# File 'lib/last-resort/config.rb', line 13

def twilio_sid
  @twilio_sid
end

Class Method Details

.populate_env_if_requiredObject



87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/last-resort/config.rb', line 87

def populate_env_if_required
  # Check if ENV is already populated
  return if ENV.has_key? 'LAST_RESORT_HOST'

  # Raises an exception if a .env can't be found
  raise "No .env file found in working directory" unless File.exists? DOT_ENV_PATH

  # Set the environment variables
  open(DOT_ENV_PATH).lines.each do |line|
    parts = line.split('=')
    ENV[parts[0]] = parts[1]
  end
end