lib/lorj_meta.rb in lorj-1.0.10 vs lib/lorj_meta.rb in lorj-1.0.11
- old
+ new
@@ -48,10 +48,19 @@
end
end
p_set(:keys => [:keys], :value => section_map, :name => 'map')
end
+ # Implement a section detection in a symbol/string
+ # Help each auto_* functions to work without update.
+ #
+ def _detect_section(key, default_section)
+ m = key.to_s.match(/^(.*)#(.*)$/)
+ return [m[1].to_sym, m[2].to_sym] if m && m[1] != '' && m[2] != ''
+ [default_section, key]
+ end
+
# set section data mapping
#
def update_map(section, data)
keys = [:keys, data]
map = p_get(:keys => keys, :name => 'map')
@@ -320,12 +329,16 @@
#
# - *:values* to get list of fixed values from :values.
#
# - :object:
#
- # Used with :query_type=:query_call. object type symbol to query.
+ # - When used with :query_type == :query_call or :controller_call,
+ # :object is the object type symbol to query.
#
+ # - When used with :query_type == :process_call, :object is the
+ # object used in the process.
+ #
# - :query
#
# Used with :query_type=:process_call. process function name to call
#
# - :query_call:
@@ -378,20 +391,42 @@
initialize_layers(config_layers)
build_section_mapping
end
+ # Redefine CoreConfig#layer_add to add mapping build
+ #
+ # See CoreConfig#layer_add for details
+ def layer_add(options)
+ p_layer_add(options)
+ build_section_mapping
+ end
+
+ # Redefine CoreConfig#layer_remove to add mapping build
+ #
+ # See CoreConfig#layer_remove for details
+ def layer_remove(options)
+ p_layer_remove(options)
+ build_section_mapping
+ end
+
# Loop on Config metadata
#
# * *Args* :
# - +code+ : Block of code on `section`, `key`, `value`
#
# * *Returns* :
# - nothing
def meta_each
data = p_get(:keys => [:sections], :merge => true)
+ if data.nil?
+ PrcLib.warning('No model data definition found. Do you have a model'\
+ ' loaded?')
+ return
+ end
+
data.each do |section, hValue|
hValue.each do |key, value|
yield section, key, value
end
end
@@ -412,39 +447,46 @@
# return 1st section/data existence.
#
# If a key name is found in several different section,
#
# auto_* functions, usually, will get the first section
- # from a key/sections mapping Array.
+ # from a key/sections mapping Array except if you provide
+ # a '#' in the data name. (Ex: :'section1#key1')
#
# The list of sections for one key is build thanks to
# build_section_mapping.
#
# * *Args* :
- # - +data+ : data name to check
+ # - +data+ : data name to check. Support 'section#data'.
#
# * *Returns* :
# - true/false
def auto_meta_exist?(data)
return nil unless data
- section = first_section(data)
+ section, data = first_section(data)
+
p_exist?(:keys => [:sections, section, data])
end
- # return the 1st section name of a data.
+ # return the 1st section name found of a data or the section discovered.
#
# * *Args* :
- # - +data+ : data name to search
+ # - +data+ : data name to search. It supports section#name.
#
# * *Returns* :
- # - 1st section name found.
+ # - Array:
+ # - section name
+ # - key name
def first_section(data)
- return nil unless p_exist?(:keys => [:keys, data])
+ section, data = _detect_section(data, nil)
+ return [section, data] unless section.nil? &&
+ p_exist?(:keys => [:keys, data])
+
arr = p_get(:keys => [:keys, data])
return nil unless arr.is_a?(Array) && arr[0]
- arr[0]
+ [arr[0], data]
end
# return the list of sections name of a data.
#
# * *Args* :
@@ -454,10 +496,11 @@
# * *Returns* :
# - Array of sections name.
def sections(data = nil)
return p_get(:keys => [:sections]).keys if data.nil?
+ _, data = _detect_section(data, nil)
return nil unless p_exist?(:keys => [:keys, data])
p_get(:keys => [:keys, data])
end
# return the list of valid keys found in meta data.
@@ -490,11 +533,11 @@
keys = [:setup]
keys.concat(options)
p_get(:keys => keys, :merge => true)
end
- # Get setup options. It returns the the top layer data for options requested
+ # Get setup options. It returns the top layer data for options requested
#
# * *Args* :
# - +options+ : Array of options tree.
#
# * *Returns* :
@@ -504,20 +547,20 @@
# - data was not found. defined in /:setup/options...
#
def setup_data(*options)
keys = [:setup]
keys.concat(options)
- p_get(:keys => keys)
+ p_get(:keys => keys, :merge => true)
end
# Get model section/data options. It returns the list of options, against
# layers, of all Hash options, cloned and merged.
#
# * *Args* :
# - +section+ : section name
# - +data+ : data name
- # - +options+ : options tree.
+ # - +options+ : Optionnal. List of sub keys in tree to get data.
#
# * *Returns* :
# - Merged cloned data options values.
# OR
# - nil if:
@@ -535,27 +578,29 @@
# Get model data options. Section name is determined by the associated
# data name
#
# auto_* functions, usually, will get the first section
- # from a key/sections mapping Array.
+ # from a key/sections mapping Array. But it supports also 'Section#Name' to
+ # determine the section to use instead of first one.
#
+ #
# The list of sections for one key is build thanks to
# build_section_mapping.
#
# * *Args* :
- # - +data+ : data name
- # - options+ : options tree.
+ # - +data+ : data name. Support 'Section#Name'
+ # - +options+ : Optionnal. List of sub keys in tree to get data.
# * *Returns* :
# - data options values
# OR
# - nil if:
# - missing data name as parameter.
# - data was not found. defined in /:sections/<section>/<data
#
def auto_section_data(data, *options)
return nil if data.nil?
- section = first_section(data)
+ section, data = first_section(data)
section_data(section, data, *options)
end
# layer setting function
#