lib/ruby-conf.rb in ruby-conf-2.7.0 vs lib/ruby-conf.rb in ruby-conf-2.7.1
- old
+ new
@@ -10,11 +10,11 @@
def self.puts(logger = $stdout, *obj) logger.puts(*obj) if logger.respond_to?(:puts) end
def self.err(*objs) self.puts($stderr, *objs) end
def self.out(*objs) self.puts($stdout, *objs) end
class Loader < BasicObject
- EXTENTIONS = %w{\\.rc \\.rbc \\.rb \\.config \\.conf \\.rbcnf \\.rconf rbconf rbconfig rubyconf rubyconfig ruby-conf ruby-config}
+ EXTENTIONS = %w{rc rb config conf rbcnf rbconf rbconfig rubyconf rubyconfig ruby-conf ruby-config}
@@conf = @@path = @@mtime = @@md5 = nil
class << self
def __rc_loaded_conf() { path:@@path, mtime:@@mtime, md5:@@md5 } end
@@ -31,19 +31,22 @@
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 =~ /(?:#{EXTENTIONS.join('|')})$/
- if !!(path =~ /(?:#{EXTENTIONS.join('|')})$/) && !!(File.read(path) =~ /^\s*\#\s*\:\s*ruby-conf\s*(?::.*)?$/mi)
- break if __rc_load(path)
- end
+ def __rc_autoload
+ Find.find('.') do |path|
+ next unless @@conf.nil? && path =~ /(?:^|\.)(?:#{EXTENTIONS.join('|')})$/
+ if (path =~ /(?:^|\.)(?:#{EXTENTIONS.join('|')})$/) && (File.read(path) =~ /^\s*\#\s*[%:=>&!;-]\s*ruby-conf\s*(?::(.*))?$/mi)
+ options = $1
+ RubyConf.err "Don't know what to do with options yet, you can have these back: #{options}" if options
+ break if __rc_load(path)
end
end
+ end
+ def method_missing(name, *args, &block)
+ __rc_reload
+ __rc_autoload if @@conf.nil?
@@conf.__send__(name, *args, &block)
end
def to_s()
__rc_reload
@@conf.to_s