lib/rib.rb in rib-0.9.0 vs lib/rib.rb in rib-0.9.1
- old
+ new
@@ -4,11 +4,11 @@
module Rib
module_function
# All default Rib configs, would be passed to Shell.new in Rib.shell,
# but calling Shell.new directly won't bring this in.
def config
- @config ||= {:config => '~/.config/rib/config.rb', :name => 'rib'}
+ @config ||= {:config => File.join(home, 'config.rb'), :name => 'rib'}
end
# All shells in the memory
def shells
@shells ||= []
@@ -17,10 +17,21 @@
# All shared variables for all shells
def vars
@vars ||= {}
end
+ # Rib.home is where Rib storing things
+ def home
+ ENV['RIB_HOME'] ||= begin
+ ['~/.rib', '~/.config/rib'].find{ |path|
+ p = File.expand_path(path)
+ File.exist?(File.join(p, 'config.rb')) ||
+ File.exist?(File.join(p, 'history.rb'))
+ } || '~/.rib'
+ end
+ end
+
# Convenient shell accessor, which would just give you current last shell
# or create one and load ~/.config/rib/config.rb if non has existed. If you
# need a clean shell which does not load rc file, use Shell.new instead.
def shell
shells.last || begin
@@ -52,10 +63,13 @@
end
# Load (actually require) ~/.config/rib/config.rb if exists.
# This might emit warnings if there's some error while loading it.
def require_config
- config_path && require(config_path)
+ return unless config_path
+ result = require(config_path)
+ Rib.say("Config loaded from: #{config_path}") if $VERBOSE && result
+ result
rescue Exception => e
Rib.warn("Error loading #{config[:config]}\n" \
" #{Rib::API.format_error(e)}")
end