|
|
@ -7,25 +7,40 @@ module HotConstants |
|
|
|
|
|
|
|
class << self |
|
|
|
def initialize |
|
|
|
LOGGER.info('initializing') |
|
|
|
env_sample = Dotenv.parse('.env.sample') |
|
|
|
env_sample.each do |key, value| |
|
|
|
dkey = key.downcase |
|
|
|
method = method_from_value(value) |
|
|
|
singleton_class.define_method(dkey) { method.call(key, value) } |
|
|
|
LOGGER.info("create method <#{dkey}> performing <#{method.name}> with default value <#{value}> ") |
|
|
|
end |
|
|
|
reload! |
|
|
|
end |
|
|
|
|
|
|
|
def stimulus_debug = load_boolean('STIMULUS_DEBUG', false) |
|
|
|
def log_active_record = load_boolean('LOG_ACTIVE_RECORD', true) |
|
|
|
def log_action_view = load_boolean('LOG_ACTION_VIEW', true) |
|
|
|
|
|
|
|
def reload! |
|
|
|
HOTENV.replace Dotenv.parse |
|
|
|
# LOGGER.warn 'reloaded!' |
|
|
|
HOTENV.replace Dotenv.parse # detect true changes before processing block below (or yield) |
|
|
|
|
|
|
|
ActiveRecord::Base.logger.level = log_active_record ? :debug : :fatal |
|
|
|
ActionView::Base.logger.level = log_action_view ? :debug : :fatal |
|
|
|
# TODO: replace with yield, thus externaliz process_block on behalf of HotEnv#initialize |
|
|
|
process_block |
|
|
|
end |
|
|
|
|
|
|
|
private |
|
|
|
|
|
|
|
def load_boolean(key, default) = HOTENV.fetch(key, default).to_s.downcase == 'true' |
|
|
|
end |
|
|
|
def load_integer(key, default) = HOTENV.fetch(key, default).to_i |
|
|
|
def load_string(key, default) = HOTENV.fetch(key, default) |
|
|
|
|
|
|
|
def method_from_value(value) |
|
|
|
case value.downcase |
|
|
|
when /^(true|false)$/ then method(:load_boolean) |
|
|
|
when /^\d+$/ then method(:load_integer) |
|
|
|
else method(:load_string) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
reload! |
|
|
|
def process_block |
|
|
|
ActiveRecord::Base.logger.level = log_active_record ? :debug : :fatal |
|
|
|
ActionView::Base.logger.level = log_action_view ? :debug : :fatal |
|
|
|
end |
|
|
|
end |
|
|
|
end |