Class: Lorj::Defaults
- Inherits:
-
PRC::SectionConfig
- Object
- PRC::BaseConfig
- PRC::SectionConfig
- Lorj::Defaults
- Defined in:
- lib/lorj_defaults.rb
Overview
meta data are defined in defaults.yaml and loaded in Lorj::Default class definition. Cloud provider can redefine ForjData defaults and add some extra parameters. To get Application defaults, read defaults.yaml, under :sections: Those values can be updated by the controller with define_data <Section>:
<Data>: Required. Symbol/String. default: nil
=> Data name. This symbol must be unique, across
sections.
:desc: Required. String. default: nil
=> Description
:explanation: |- Print a multiline explanation before ask the key
value.
ERB template enable. To get config data,
type <%= config[...] %>
:readonly: Optional. true/false. Default: false
=> oForjConfig.set() will fail if readonly is
true. It can be set, only thanks to:
- oForjConfig.setup()
or using private
- oForjConfig._set()
:account_exclusive: Optional. true/false. Default: false
=> Only oConfig.account_get/set() can handle the
value
oConfig.set/get cannot.
:account: Optional. default: False
=> setup will configure the account with this
<Data>
:ask_sort: Number which represents the ask order in the
step group. (See /:setup/:ask_step for details)
:after: <Data> Name of the previous <Data> to ask before the
current one.
:depends_on:
=> Identify :data type required to be set before
the current one.
:default_value: Default value at setup time. This is not
necessarily the Application default value
(See /:default)
:validate: Regular expression to validate end user input
during setup.
:value_mapping: list of values to map as defined by the
controller
:controller: mapping for get controller value from process
values
<value> : <map> value map equivalence. See data_value_mapping
function
:process: mapping for get process value from controller
values
<value> : <map> value map equivalence. See data_value_mapping
function
:default: Default value. Replace /:default/<data>
:list_values: Defines a list of valid values for the current
data.
:query_type :controller_call to execute a function defined
in the controller object.
:process_call to execute a function defined in
the process object.
:values to get list of values from :values.
:object Object to load before calling the function.
Only :query_type = :*_call
:query_call Symbol. function name to call.
Only :query_type = :*_call
function must return an Array.
:query_params Hash. Controler function parameters.
Only :query_type = :*_call
:validate :list_strict. valid only if value is one of
thoselisted.
:values: to retrieve from.
otherwise define simply a list of possible
values.
:ask_step: Step number. By default, setup will determine
the step, thanks to lorj object
dependencies tree.
This number start at 0. Each step can be defined
by /:setup/:ask_step/<steps> list.
:pre_step_function: Process called before asking the data.
if it returns true, user interaction is
cancelled.
:post_step_function:Process called after asking the data.
if it returns false, the user is requested to
re-enter a new value.
:setup: This section describes group of fields to ask,
step by step.
:ask_step: Define an Array of setup steps to ask to the
end user. The step order is respected, and
start at 0
- :desc: Define the step description. ERB template
enable. To get config data, type config[...]
:explanation: |- Define a multiline explanation. This is printed
out in brown color.
ERB template enable. To get config data, type
<%= config[...] %>
:add: Define a list of additionnal fields to ask.
- <Data> Data to ask.
Instance Attribute Summary
Attributes inherited from PRC::BaseConfig
Instance Method Summary collapse
-
#[]=(*_keys, _value) ⇒ Object
Remove inherited method []=.
-
#build_section_mapping ⇒ Object
-
Args : - ++ -> * Returns : - * Raises : - ++ ->.
-
-
#get_meta(*keys) ⇒ Object
Get model section/data options.
-
#get_meta_auto(*keys) ⇒ Object
Get model data options.
-
#get_meta_section(key) ⇒ Object
-
Args : - ++ -> * Returns : - * Raises : - ++ ->.
-
-
#load ⇒ Object
-
Args : - ++ -> * Returns : - * Raises : - ++ ->.
-
-
#meta_each ⇒ Object
Loop on Config metadata.
-
#meta_exist?(key) ⇒ Boolean
-
Args : - ++ -> * Returns : - * Raises : - ++ ->.
-
Methods inherited from PRC::SectionConfig
Methods inherited from PRC::BaseConfig
#[], #data_options, #del, #erase, #exist?, #initialize, #rh_key_to_symbol, #rh_key_to_symbol?, #save, #to_s
Constructor Details
This class inherits a constructor from PRC::BaseConfig
Instance Method Details
#[]=(*_keys, _value) ⇒ Object
Remove inherited method []=
299 300 |
# File 'lib/lorj_defaults.rb', line 299 def []=(*_keys, _value) end |
#build_section_mapping ⇒ Object
-
Args :
-
++ ->
-
-
Returns : -
-
Raises :
-
++ ->
-
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 |
# File 'lib/lorj_defaults.rb', line 395 def build_section_mapping if @data.rh_get(:sections).nil? PrcLib.warning('defaults.yaml do not defines :sections') return nil end # TODO: Support multiple identical key name on distinct sections # The primary data key should change from key to section & key. @data.rh_get(:sections).each do |section, hValue| next if section == :default hValue.each_key do |map_key| if @account_section_mapping.rh_exist?(map_key) PrcLib.fatal(1, 'defaults.yaml: Duplicate entry between sections. '\ "'%s' defined in section '%s' already exists in"\ " section '%s'", map_key, section, @account_section_mapping.rh_get(map_key)) end @account_section_mapping.rh_set(section, map_key) end end end |
#get_meta(*keys) ⇒ Object
Get model section/data options.
-
Args :
-
section: section name -
data: data name -
options: options tree.
-
-
Returns :
-
data options values
OR
-
nil if:
-
missing section and data name as parameter.
-
data was not found. defined in /:sections/<section>/<data
-
-
-
Raises :
-
++ ->
-
382 383 384 385 |
# File 'lib/lorj_defaults.rb', line 382 def (*keys) return nil unless keys.length > 1 @data.rh_get(:sections, keys) end |
#get_meta_auto(*keys) ⇒ Object
Get model data options. Section name is determined by the associated data name
-
Args :
-
data: data name -
options+ : options tree.
-
-
Returns :
-
data options values
OR
-
nil if:
-
missing data name as parameter.
-
data was not found. defined in /:sections/<section>/<data
-
-
-
Raises :
-
++ ->
-
355 356 357 358 359 360 |
# File 'lib/lorj_defaults.rb', line 355 def (*keys) return nil unless keys.length > 0 section = @account_section_mapping.rh_get(keys[0]) return nil if section.nil? @data.rh_get(:sections, section, keys) end |
#get_meta_section(key) ⇒ Object
-
Args :
-
++ ->
-
-
Returns : -
-
Raises :
-
++ ->
-
425 426 427 428 |
# File 'lib/lorj_defaults.rb', line 425 def (key) key = key.to_sym if key.class == String @account_section_mapping.rh_get(key) end |
#load ⇒ Object
-
Args :
-
++ ->
-
-
Returns : -
-
Raises :
-
++ ->
-
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 |
# File 'lib/lorj_defaults.rb', line 438 def load @account_section_mapping = {} if !PrcLib.app_defaults PrcLib.warning('PrcLib.app_defaults is not set. Application defaults'\ " won't be loaded.") else @filename = File.join(PrcLib.app_defaults, 'defaults.yaml') PrcLib.info("Reading default configuration '%s'...", @filename) if File.exist?(@filename) _load(@filename) 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, @filename) end end end |
#meta_each ⇒ Object
Loop on Config metadata
-
Args :
-
++ ->
-
-
Returns : -
-
Raises :
-
++ ->
-
314 315 316 317 318 319 320 321 322 |
# File 'lib/lorj_defaults.rb', line 314 def return nil if @data.rh_get(:sections).nil? @data.rh_get(:sections).each do |section, hValue| hValue.each do |key, value| yield section, key, value end end end |
#meta_exist?(key) ⇒ Boolean
-
Args :
-
++ ->
-
-
Returns : -
-
Raises :
-
++ ->
-
332 333 334 335 336 337 338 339 |
# File 'lib/lorj_defaults.rb', line 332 def (key) return nil unless key key = key.to_sym if key.class == String section = @account_section_mapping.rh_get(key) @data.rh_exist?(:sections, section, key) end |