lib/ruby-conf.rb in ruby-conf-2.6.1 vs lib/ruby-conf.rb in ruby-conf-2.6.2
- old
+ new
@@ -15,39 +15,53 @@
EXTENTIONS = %w{rbc rbcnf rbconf rbconfig rubyconf rubyconfig ruby-conf ruby-config}
@@conf = @@path = @@mtime = @@md5 = nil
class << self
- def nil?() @@conf.nil? end
def __rc_loaded_conf() { path:@@path, mtime:@@mtime, md5:@@md5 } end
def __rc_conf() @@conf end
def __rc_set_conf(conf = nil) @@conf, @@path, @@mtime, @@md5 = conf, nil, nil, nil end
def __rc_load(path)
__rc_set_conf
if load(path) && @@conf
@@path, @@mtime, @@md5 = path, File.mtime(path).to_i, Digest::MD5.hexdigest(File.read(path))
RubyConf.out "[ruby-conf] Auto-Loaded config at path: #{path}"
end
end
- def method_missing(name, *args, &block)
+ def __rc_reload
if @@mtime && @@mtime != File.mtime(@@path).to_i && @@md5 != Digest::MD5.hexdigest(File.read(@@path))
RubyConf.err "[ruby-conf] Detected change in config file, reloading..."
__rc_load(@@path)
end
-
+ end
+ def method_missing(name, *args, &block)
+ __rc_reload
if @@conf.nil?
Find.find('.') do |path|
next unless @@conf.nil? && path =~ /\.(?:rb|config|conf|#{EXTENTIONS.join('|')})$/
if path =~ /\.(?:#{EXTENTIONS.join('|')})$/ || File.read(path) =~ /^\s*\#\s*\:\s*ruby-conf\s*$/mi
break if __rc_load(path)
end
end
end
@@conf.__send__(name, *args, &block)
end
- def to_s() @@conf.to_s end
- def to_str() @@conf.to_str end
- def inspect() @@conf.inspect end
+ def to_s()
+ __rc_reload
+ @@conf.to_s
+ end
+ def to_str()
+ __rc_reload
+ @@conf.to_str
+ end
+ def inspect()
+ __rc_reload
+ @@conf.inspect
+ end
+ def nil?()
+ __rc_reload
+ @@conf.nil?
+ end
end
end
module Magic
attr_accessor :__rc_chain