lib/lorj_config.rb in lorj-1.0.3 vs lib/lorj_config.rb in lorj-1.0.4

- old
+ new

@@ -15,10 +15,11 @@ # limitations under the License. require 'rubygems' require 'yaml' +# Definition of Lorj::Config module Lorj # Lorj::Config is a generic class for configuration management. # It is used by lorj to get/set data # # lorj uses following function in different context: @@ -99,32 +100,36 @@ # If config doesn't exist, it will be created, empty with 'defaults:' only # # # * *Args* : # - +config_name+ : Config file name to use. By default, file path is - # built as PrcLib.data_path+'config.yaml' + # built as #{PrcLib.data_path}/config.yaml # * *Returns* : # - # * *Raises* : # - ++ -> def initialize(config_name = nil) config_layers = [] # Application layer config_layers << define_default_layer + # runtime Config layer + config_layers << define_controller_data_layer + # Local Config layer - config_layers << define_local_layer + local = define_local_layer + config_layers << local # runtime Config layer config_layers << define_runtime_layer if PrcLib.data_path.nil? PrcLib.fatal(1, 'Internal PrcLib.data_path was not set.') end - initialize_local(config_layers[1][:config], config_name) + initialize_local(local[:config], config_name) initialize_layers(config_layers) end def define_default_layer @@ -137,10 +142,14 @@ PRC::CoreConfig.define_layer(:name => 'local', :config => PRC::SectionConfig.new, :load => true, :save => true) end + def define_controller_data_layer + PRC::CoreConfig.define_layer :name => 'controller' + end + def define_runtime_layer PRC::CoreConfig.define_layer end def initialize_local(config, config_name = nil) @@ -228,11 +237,11 @@ # * *Returns* : # value found or default # * *Raises* : # nothing def [](key, default = nil) # Re-define PRC::CoreConfig []= function - return _get(:keys => [key]) if exist?(key) + return p_get(:keys => [key]) if exist?(key) default end # get_section helps to identify in which section the data is defined by # data model of the application. @@ -286,24 +295,9 @@ # * *Raises* : # Nothing def runtime_get(key) index = layer_index('runtime') @config_layers[index][:config][key] - end - - # Get Application data - # Used to get any kind of section available in the Application default.yaml. - # - # * *Args* : - # - +section+ : section name to get the key. - # - +keys_tree+ : list of key name tree - # * *Returns* : - # value found - # * *Raises* : - # nothing - def app_default(*keys) - return Lorj.defaults.data.rh_get(*keys) if keys.length > 0 - nil end # Save the config.yaml file. # # * *Args* :