lib/egi.rb in egi-0.0.2 vs lib/egi.rb in egi-0.0.3
- old
+ new
@@ -5,22 +5,39 @@
autoload :Env, 'egi/env'
autoload :Group, 'egi/group'
autoload :Item, 'egi/item'
def env
+ load_file(config_file) unless @env
+
name = ENV['EGI_ENV'] || 'default'
self[name]
end
def [](name)
@env.has_key?(name) ? @env[name] : nil
end
+ def load_file(file)
+ load(File.read(file))
+ end
+
def load(str)
@env = Sandbox.new.eval(str)
end
def reset
@env = nil
end
- module_function :[], :load, :reset
+ def config_file
+ @config_file ||
+ ( File.exist?('./egi.conf') && './egi.conf' ) ||
+ ( File.exist?('/etc/egi.conf') && '/etc/egi.conf') ||
+ raise('you should set Egi.config_file or put ./egi.conf or /etc/egi.conf')
+ end
+
+ def config_file=(file)
+ @config_file = file
+ end
+
+ module_function :env, :[], :load, :reset, :config_file, :config_file=
end