lib/prc-config.rb in lorj-0.1.0 vs lib/prc-config.rb in lorj-0.2.0
- old
+ new
@@ -150,11 +150,11 @@
# rhSet(yVal, :test, :test5 ) => :test
# # yVal = {:test2 => {:test5 => :test}, :test5 => :test }
#
# rhSet(yVal, 'blabla', :test2, 'text') => :test
# # yVal = {:test2 => {:test5 => :test, 'text' => 'blabla'}, :test5 => :test }
- def Lorj::rhSet(yVal, value, *p)
+ def self::rhSet(yVal, value, *p)
if p.length() == 0
return yVal
end
p=p.flatten
if p.length() == 1
@@ -190,11 +190,11 @@
# - +levels+: level of key tree to update.
# * *Returns* :
# - hash of hashes updated.
# * *Raises* :
# Nothing
- def Lorj.rhKeyToSymbol(yVal, levels = 1)
+ def self.rhKeyToSymbol(yVal, levels = 1)
return nil if yVal.nil? or yVal.class != Hash
yRes = {}
yVal.each { | key, value |
if key.class == String
if levels <= 1
@@ -221,11 +221,11 @@
# * *Returns* :
# - true : one key path is not symbol.
# - false : all key path are symbols.
# * *Raises* :
# Nothing
- def Lorj.rhKeyToSymbol?(yVal, levels = 1)
+ def self.rhKeyToSymbol?(yVal, levels = 1)
return false if yVal.nil? or yVal.class != Hash
yVal.each { | key, value |
if key.class == String
return true
end
@@ -358,10 +358,12 @@
# * *Returns* :
# -
# * *Raises* :
# - ++ ->
def self.meta_each
+ return nil if Lorj::rhGet(@@yDefaults, :sections).nil?
+
Lorj::rhGet(@@yDefaults, :sections).each { | section, hValue |
hValue.each { | key, value |
yield section, key, value
}
}
@@ -456,12 +458,17 @@
else
@@sDefaultsName = File.join(PrcLib.app_defaults,'defaults.yaml')
PrcLib.info("Reading default configuration '%s'..." % @@sDefaultsName)
- @@yDefaults = YAML.load_file(@@sDefaultsName)
+ if File.exists?(@@sDefaultsName)
+ @@yDefaults = YAML.load_file(@@sDefaultsName)
- self.build_section_mapping
+ self.build_section_mapping
+ else
+ PrcLib.warning("PrcLib.app_defaults is set to '%s'. Trying to load '%s' but not found. Application defaults won't be loaded." % [PrcLib.app_defaults, @@sDefaultsName])
+ end
+
end
end
end