Skip to content

Commit

Permalink
Rename constants for config option types
Browse files Browse the repository at this point in the history
We no longer use these constants only to read from the ENV vars, so
rename the constants so they make more sense in context.
  • Loading branch information
tombruijn committed Oct 23, 2024
1 parent bce4e97 commit 0976d37
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
24 changes: 12 additions & 12 deletions lib/appsignal/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def self.determine_root_path
}.freeze

# @api private
ENV_STRING_KEYS = {
STRING_OPTIONS = {
"APPSIGNAL_ACTIVEJOB_REPORT_ERRORS" => :activejob_report_errors,
"APPSIGNAL_APP_NAME" => :name,
"APPSIGNAL_BIND_ADDRESS" => :bind_address,
Expand All @@ -140,7 +140,7 @@ def self.determine_root_path
"APP_REVISION" => :revision
}.freeze
# @api private
ENV_BOOLEAN_KEYS = {
BOOLEAN_OPTIONS = {
"APPSIGNAL_ACTIVE" => :active,
"APPSIGNAL_ENABLE_ALLOCATION_TRACKING" => :enable_allocation_tracking,
"APPSIGNAL_ENABLE_AT_EXIT_REPORTER" => :enable_at_exit_reporter,
Expand All @@ -164,7 +164,7 @@ def self.determine_root_path
"APPSIGNAL_SEND_SESSION_DATA" => :send_session_data
}.freeze
# @api private
ENV_ARRAY_KEYS = {
ARRAY_OPTIONS = {
"APPSIGNAL_DNS_SERVERS" => :dns_servers,
"APPSIGNAL_FILTER_METADATA" => :filter_metadata,
"APPSIGNAL_FILTER_PARAMETERS" => :filter_parameters,
Expand All @@ -176,7 +176,7 @@ def self.determine_root_path
"APPSIGNAL_REQUEST_HEADERS" => :request_headers
}.freeze
# @api private
ENV_FLOAT_KEYS = {
FLOAT_OPTIONS = {
"APPSIGNAL_CPU_COUNT" => :cpu_count
}.freeze

Expand Down Expand Up @@ -470,31 +470,31 @@ def load_from_environment
config = {}

# Configuration with string type
ENV_STRING_KEYS.each do |env_key, option|
STRING_OPTIONS.each do |env_key, option|
env_var = ENV.fetch(env_key, nil)
next unless env_var

config[option] = env_var
end

# Configuration with boolean type
ENV_BOOLEAN_KEYS.each do |env_key, option|
BOOLEAN_OPTIONS.each do |env_key, option|
env_var = ENV.fetch(env_key, nil)
next unless env_var

config[option] = env_var.casecmp("true").zero?
end

# Configuration with array of strings type
ENV_ARRAY_KEYS.each do |env_key, option|
ARRAY_OPTIONS.each do |env_key, option|
env_var = ENV.fetch(env_key, nil)
next unless env_var

config[option] = env_var.split(",")
end

# Configuration with float type
ENV_FLOAT_KEYS.each do |env_key, option|
FLOAT_OPTIONS.each do |env_key, option|
env_var = ENV.fetch(env_key, nil)
next unless env_var

Expand Down Expand Up @@ -550,7 +550,7 @@ def env
@config.env
end

Appsignal::Config::ENV_STRING_KEYS.each_value do |option|
Appsignal::Config::STRING_OPTIONS.each_value do |option|
define_method(option) do
fetch_option(option)
end
Expand All @@ -560,7 +560,7 @@ def env
end
end

Appsignal::Config::ENV_BOOLEAN_KEYS.each_value do |option|
Appsignal::Config::BOOLEAN_OPTIONS.each_value do |option|
define_method(option) do
fetch_option(option)
end
Expand All @@ -570,7 +570,7 @@ def env
end
end

Appsignal::Config::ENV_ARRAY_KEYS.each_value do |option|
Appsignal::Config::ARRAY_OPTIONS.each_value do |option|
define_method(option) do
fetch_option(option)
end
Expand All @@ -580,7 +580,7 @@ def env
end
end

Appsignal::Config::ENV_FLOAT_KEYS.each_value do |option|
Appsignal::Config::FLOAT_OPTIONS.each_value do |option|
define_method(option) do
fetch_option(option)
end
Expand Down
8 changes: 4 additions & 4 deletions spec/lib/appsignal/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ def on_load
it "reads all string env keys" do
config

Appsignal::Config::ENV_STRING_KEYS.each do |env_key, option|
Appsignal::Config::STRING_OPTIONS.each do |env_key, option|
ENV.fetch(env_key) { raise "Config env var '#{env_key}' is not set for this test" }
expect(config[option]).to eq(ENV.fetch(env_key, nil))
end
Expand All @@ -627,7 +627,7 @@ def on_load
it "reads all boolean env keys" do
config

Appsignal::Config::ENV_BOOLEAN_KEYS.each do |env_key, option|
Appsignal::Config::BOOLEAN_OPTIONS.each do |env_key, option|
ENV.fetch(env_key) { raise "Config env var '#{env_key}' is not set for this test" }
expect(config[option]).to eq(ENV.fetch(env_key, nil) == "true")
end
Expand All @@ -636,7 +636,7 @@ def on_load
it "reads all array env keys" do
config

Appsignal::Config::ENV_ARRAY_KEYS.each do |env_key, option|
Appsignal::Config::ARRAY_OPTIONS.each do |env_key, option|
ENV.fetch(env_key) { raise "Config env var '#{env_key}' is not set for this test" }
expect(config[option]).to eq(ENV.fetch(env_key, nil).split(","))
end
Expand All @@ -645,7 +645,7 @@ def on_load
it "reads all float env keys" do
config

Appsignal::Config::ENV_FLOAT_KEYS.each do |env_key, option|
Appsignal::Config::FLOAT_OPTIONS.each do |env_key, option|
ENV.fetch(env_key) { raise "Config env var '#{env_key}' is not set for this test" }
expect(config[option]).to eq(ENV.fetch(env_key, nil).to_f)
end
Expand Down

0 comments on commit 0976d37

Please sign in to comment.