|
@ -7,6 +7,7 @@ module HotConstants |
|
|
|
|
|
|
|
|
class << self |
|
|
class << self |
|
|
def initialize |
|
|
def initialize |
|
|
|
|
|
@on_change_listeners = {} |
|
|
env_sample = Dotenv.parse('.env.sample') # TODO: able to detect add/remove, then either call define_method or undef_method! |
|
|
env_sample = Dotenv.parse('.env.sample') # TODO: able to detect add/remove, then either call define_method or undef_method! |
|
|
env_sample.each do |key, value| |
|
|
env_sample.each do |key, value| |
|
|
dkey = key.downcase |
|
|
dkey = key.downcase |
|
@ -18,10 +19,16 @@ module HotConstants |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
def reload! |
|
|
def reload! |
|
|
HOTENV.replace Dotenv.parse # detect true changes before processing block below (or yield) |
|
|
|
|
|
|
|
|
HOTENV.replace Dotenv.parse # TODO: detect true changes before processing block below (or yield) |
|
|
|
|
|
@on_change_listeners.each_pair do |key, block| |
|
|
|
|
|
old_value = nil # TODO: remember last previous value |
|
|
|
|
|
new_value = method(key).call |
|
|
|
|
|
block.call(new_value) |
|
|
|
|
|
end |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
# TODO: replace with yield, thus externaliz process_block on behalf of HotEnv#initialize |
|
|
|
|
|
process_block |
|
|
|
|
|
|
|
|
def on_change(key, &block) |
|
|
|
|
|
@on_change_listeners[key.downcase.to_sym] = block |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
private |
|
|
private |
|
@ -37,10 +44,5 @@ module HotConstants |
|
|
else method(:load_string) |
|
|
else method(:load_string) |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
def process_block |
|
|
|
|
|
ActiveRecord::Base.logger.level = log_active_record ? :debug : :fatal |
|
|
|
|
|
ActionView::Base.logger.level = log_action_view ? :debug : :fatal |
|
|
|
|
|
end |
|
|
|
|
|
end |
|
|
end |
|
|
end |
|
|
end |