|
|
@ -15,24 +15,28 @@ module HotConstants |
|
|
|
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 reload! |
|
|
|
HOTENV.replace Dotenv.parse # TODO: detect true changes before processing block below (or yield) |
|
|
|
LISTENERS.each_pair do |key, block| |
|
|
|
old_value = nil # TODO: remember last previous value |
|
|
|
new_value = method(key).call |
|
|
|
block.call(new_value, old_value) |
|
|
|
perform_change(key, block) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
def on_change(key, &block) |
|
|
|
LISTENERS[key.downcase.to_sym] = block |
|
|
|
perform_change(key, block) |
|
|
|
end |
|
|
|
|
|
|
|
private |
|
|
|
|
|
|
|
def perform_change(key, block) |
|
|
|
old_value = nil # TODO: remember last previous value |
|
|
|
new_value = method(key).call |
|
|
|
block.call(new_value, old_value) |
|
|
|
end |
|
|
|
|
|
|
|
def load_boolean(key, default) = HOTENV.fetch(key, default).to_s.downcase == 'true' |
|
|
|
def load_integer(key, default) = HOTENV.fetch(key, default).to_i |
|
|
|
def load_string(key, default) = HOTENV.fetch(key, default) |
|
|
@ -45,4 +49,7 @@ module HotConstants |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
# initialize on first require |
|
|
|
initialize |
|
|
|
end |