class Lorj::BaseDefinition

Adding controller core functions.

Implements account_import and account_export exposed by core.

Class Definition internal function.

Adding process core functions.

Adding private process core functions.

Adding process core functions.

Adding process core functions.

Adding encrypt core functions.

Adding process core functions.

Adding process core functions.

Global Process functions

Base definition class for Process declaration

Completing BaseDefinition with Exclusive controller functions

Completing BaseDefinition with internal functions

Completing BaseDefinition with internal functions for obj_needs

Class Definition internal function.

Following class defines class levels function to declare framework objects. As each process needs to define new object to deal with require that process to define it with definition functions See definition.rb for functions to use.

Attributes

obj_type[W]

Public Class Methods

_configure_options_handlers(options) click to toggle source

Internal function

# File lib/core/definition.rb, line 587
def self._configure_options_handlers(options)
  for_events = PrcLib.model.meta_obj.rh_get(PrcLib.model.object_context,
                                            :lambdas).keys
  options.merge(:for => for_events) unless options.key?(:for)
end
_decl_data_valid?(value, map) click to toggle source

Internal model data validation return true if valid. false otherwise.

# File lib/core/definition.rb, line 540
def self._decl_data_valid?(value, map)
  return false unless [String, Symbol].include?(value.class)
  return false unless [NilClass, Symbol, String].include?(map.class)
  true
end
_decl_object_attr_valid?(key, map, options) click to toggle source

Internal model data validation return true if valid. false otherwise.

# File lib/core/definition.rb, line 530
def self._decl_object_attr_valid?(key, map, options)
  return false unless [String, Symbol].include?(key.class)
  return false unless options.is_a?(Hash)
  return false unless [Symbol, String, Array].include?(map.class)

  true
end
_define_obj_initialize(obj_type_name, handlers) click to toggle source

Internal function

# File lib/core/definition.rb, line 627
def self._define_obj_initialize(obj_type_name, handlers)
  use_controller = PrcLib.model[:use_controller]

  if use_controller.nil?
    PrcLib.model.options :use_controller => true
    use_controller = true
  end

  # TODO: Cleanup un-used 2 levels :params/:keys by single :params
  object = { :lambdas => { :create_e => nil, :delete_e => nil,
                           :update_e => nil, :get_e => nil,
                           :query_e => nil, :get_attr_e => nil,
                           :refresh_e => nil },
             :params =>  { :keys => {} },
             :options => { :controller => use_controller },
             :query_mapping => { ':id' => ':id', ':name' => ':name' },
             :returns => { ':id' => ':id', ':name' => ':name' }
           }

  PrcLib.dcl_fail("A new declared object '%s' requires at "\
                  'least one handler. Ex: define_obj :%s, '\
                  'create_e: myhandler or nohandler: true',
                  obj_type_name,
                  obj_type_name) if handlers.length == 0

  if !handlers.rh_get(:nohandler)
    msg = '%-28s object declared.'
  else
    msg = '%-28s meta object declared.'
  end
  Lorj.debug(2, msg, _object_name(obj_type_name))
  object
end
_define_object_needs(params, type, msg_action, options) click to toggle source

Internal function

# File lib/core/definition.rb, line 571
def self._define_object_needs(params, type, msg_action, options)
  attribute = PrcLib.model.attribute_context

  case type
  when :data
    return _obj_needs_data(params[:keys][attribute.fpath],
                           msg_action, options)
  when :CloudObject, :object
    return _obj_needs_object(params[:keys][attribute.fpath],
                             options)
  end
  PrcLib.dcl_fail("%s: Object parameter type '%s' unknown.",
                  self.class, type)
end
_handler_settings(object, handlers_options) click to toggle source

Setting procs

# File lib/core/definition.rb, line 687
def self._handler_settings(object, handlers_options)
  handlers_dcl = object[:lambdas]
  process_context = PrcLib.model.process_context

  handlers_dcl.each_key do |key|
    next unless handlers_options.key?(key)

    # Warning! Use BaseProcess._instance_methods Compatibility function
    # instead of BaseProcess.instance_methods
    unless process_context._instance_methods.include?(handlers_options[key])
      PrcLib.dcl_fail("'%s' parameter requires a valid instance method"\
                      " '%s' in the process '%s'.",
                      key, handlers_options[key], process_context)
    end
    if handlers_options[key] == :default
      # By default, we use the event name as default function to call.
      # Those function are predefined in ForjController
      # The Provider needs to derive from ForjController and redefine those
      # functions.
      object[:lambdas][key] = key
    else
      # If needed, ForjProviver redefined can contains some additionnal
      # functions to call.
      object[:lambdas][key] = handlers_options[key]
    end
  end
end
_initialize_object_needs(name) click to toggle source

Internal function for obj_needs Initialize :params/:keys/

# File lib/core/definition.rb, line 555
def self._initialize_object_needs(name)
  top_param_obj = PrcLib.model.meta_obj.rh_get(PrcLib.model.object_context,
                                               :params)

  PrcLib.model.attribute_context KeyPath.new(name)
  key_access = PrcLib.model.attribute_context.fpath

  unless top_param_obj[:keys].key?(key_access)
    top_param_obj[:keys][key_access] = {}
    return 'New'
  end

  'Upd'
end
_obj_needs_data(object_attr, msg_action, new_params) click to toggle source

Internal function

# File lib/core/definition.rb, line 598
def self._obj_needs_data(object_attr, msg_action, new_params)
  attr_name = PrcLib.model.attribute_context
  if Lorj.data.auto_meta_exist?(attr_name)
    Lorj.debug(2, "%-28s: %s predefined config '%s'.",
               _object_name(PrcLib.model.object_context),
               msg_action, attr_name)
  else
    Lorj.debug(2, "%-28s: %s runtime    config '%s'.",
               _object_name(PrcLib.model.object_context),
               msg_action, attr_name)
  end
  # Merge from predefined params, but ensure type is never updated.
  object_attr.merge!(new_params.merge(:type => :data))
end
_obj_needs_object(object_attr, new_params) click to toggle source

Internal function

# File lib/core/definition.rb, line 614
def self._obj_needs_object(object_attr, new_params)
  attr_name = PrcLib.model.attribute_context
  unless PrcLib.model.meta_obj.key?(attr_name.key)
    PrcLib.dcl_fail("%s: '%s' not declared. Missing define_obj(%s)?",
                    self.class,
                    attr_name,
                    attr_name)
  end
  # Merge from predefined params, but ensure type is never updated.
  object_attr.merge!(new_params.merge(:type => :CloudObject))
end
_object_name(name) click to toggle source

Internal function to get the object_name as class.object

return formated string.

# File lib/core/definition.rb, line 549
def self._object_name(name)
  format("'%s.%s'", self.class, name)
end
_query_mapping(key, map) click to toggle source

Internal function

# File lib/core/definition.rb, line 482
def self._query_mapping(key, map)
  return nil unless [String, Symbol].include?(key.class)
  return nil unless [NilClass, Symbol, String, Array].include?(map.class)

  object_type = PrcLib.model.object_context
  key_path = KeyPath.new(key)
  map_path_obj = KeyPath.new(map)

  PrcLib.model.attribute_context key_path

  PrcLib.model.meta_obj.rh_set(map_path_obj.fpath, object_type,
                               :query_mapping, key_path.fpath)
end
_section_from(data) click to toggle source

Internal section detection based on a keyPath Object

# File lib/core/definition.rb, line 520
def self._section_from(data)
  return data.key[0] if data.length == 2
  section = Lorj.defaults.get_meta_section(data.key)
  section = :runtime if section.nil?

  section
end
_set_attr_mapping(key, map, options) click to toggle source

Internal function to store object attribute and mapping information parameters:

# File lib/core/definition.rb, line 501
def self._set_attr_mapping(key, map, options)
  return nil unless _decl_object_attr_valid?(key, map, options)

  object_type = PrcLib.model.object_context
  key_path_obj = KeyPath.new(key)

  map_path_obj = KeyPath.new(map)

  PrcLib.model.meta_obj.rh_set(map_path_obj.fpath, object_type,
                               :returns, key_path_obj.fpath)

  PrcLib.model.attribute_context key_path_obj

  return if options[:not_queriable] == true
  query_mapping(key, map)
  [key_path_obj.fpath, map_path_obj.fpath]
end
_verify_handlers(type_name, object, handlers) click to toggle source

Internal function for define_obj Check handler options. Return the list of handlers set if handler list is ok (exist 1 at least) return false if no handler is set.

# File lib/core/definition.rb, line 665
def self._verify_handlers(type_name, object, handlers)
  return false if handlers.rh_get(:nohandler)

  PrcLib.dcl_fail("A new declared object '%s' requires at "\
                  'least one handler. Ex: define_obj :%s, '\
                  'create_e: myhandler or nohandler: true',
                  type_name, type_name) if object.nil? &&
                                           handlers.length == 0

  return handlers if object.nil?

  handlers_list = object[:lambdas].keys.join(', ')
  handlers.each_key do |key|
    next if object.rh_exist?(:lambdas, key)

    PrcLib.dcl_fail("'%s' parameter is invalid. Use '%s'",
                    key, handlers_list)
  end
  handlers
end
attr_value_mapping(value, map) click to toggle source

Controller to declare an lorj object attribute data mapping.

You need to define object and attribute context before attr_value_mapping

parameters:

  • value : name of the default object attribute

  • map : Map a predefined object attribute value.

Ex: If the application model has defined:

   :server[:status] = [:create, :boot, :active]

define_obj :server # Required to set object context
get_attr_mapping :status, :state # set attribute mapping and context.
attr_value_mapping :create, 'BUILD'
attr_value_mapping :boot,   :boot
attr_value_mapping :active, 'ACTIVE'
# File lib/core/definition.rb, line 395
def self.attr_value_mapping(value, map)
  PrcLib.model.heap true

  return nil unless _decl_data_valid?(value, map)

  object_type = PrcLib.model.object_context

  key_path = PrcLib.model.attribute_context __callee__

  keypath = key_path.fpath
  Lorj.debug(2, "%s-%s: Attribute value mapping '%s' => '%s'",
             object_type, key_path.to_s, value, map)
  PrcLib.model.meta_obj.rh_set(map,
                               object_type, :value_mapping, keypath, value)
end
current_process(cProcessClass) click to toggle source

Process declaration Defines current Process context

parameters:

  • process_class : Process Class object.

# File lib/core/definition.rb, line 36
def self.current_process(cProcessClass)
  PrcLib.model.heap true
  PrcLib.model.process_context(cProcessClass)
end
data_value_mapping(value, map) click to toggle source

Controller to declare a model Data value mapping

Parameters:

  • value : Value to map

  • map : Value mapped

# File lib/core/definition.rb, line 301
def self.data_value_mapping(value, map)
  return nil unless _decl_data_valid?(value, map)
  PrcLib.model.heap true

  data = PrcLib.model.data_context

  section = _section_from(data)

  Lorj.debug(2, format("%s/%s: Define config data value mapping: '%s' => "\
                       "'%s'", section, data.fpath, value, map))
  PrcLib.model.meta_data.rh_set(map, section, data,
                                :value_mapping,  :controller, value)
  PrcLib.model.meta_data.rh_set(value, section, data,
                                :value_mapping,  :process, map)
end
def_attr_mapping(key, map, options = {}) click to toggle source

Function used by the controler to define mapping. By default, any attributes are queriable as well. No need to call query_mapping

parameters:

  • key : name of the default object attribute

  • map : optional.

  • options: optional.

# File lib/core/definition.rb, line 370
def self.def_attr_mapping(key, map, options = {})
  PrcLib.model.heap true
  key_paths = _set_attr_mapping(key, map, options)

  Lorj.debug(4, "%s: Defining object attribute mapping '%s' => '%s'",
             PrcLib.model.object_context, key_paths[0], key_paths[1])
end
def_attribute(key, options = {}) click to toggle source

Function used by the Process to define Model Object attributes. By default, any attributes are queriable as well. No need to call query_mapping

parameters:

  • key : name of the default object attribute

  • options: optional.

# File lib/core/definition.rb, line 233
def self.def_attribute(key, options = {})
  PrcLib.model.heap true

  key_path = _set_attr_mapping(key, key, options)[0]

  Lorj.debug(4, "%s: Defining object attribute '%s'",
             PrcLib.model.object_context, key_path)
end
def_hdata(attr_name, options = {}) click to toggle source

Controller to declare predefined Hash options for controller wrapper code.

When a controller wrapper code is called to execute a function, the controller may/should provides some options.

lorj framework can simplify the way to call this function and provide a predefined options list, prepared by lorj.

Ex: If you are calling a connection function, which requires one

or more parameters passed as an Hash:

wrapper code without using :hdata:

def connect(params)
   options = { :hp_access_key => params[:account_id],
               :hp_secret_key => params[:account_key]
               :hp_auth_uri => params[:auth_uri]
               :hp_tenant_id => params[:tenant]
               :hp_avl_zone => params[:network]
   }
   Fog::HP::Network.new(options)
end

wrapper code using :hdata and def_hdata:

def connect(params)
   Fog::HP::Network.new(params[:hdata])
end

def_hdata requires the object context. Ex:

define_obj(:student)
def_hdata :first_name
def_hdata :last_name
def_hdata :course,      mapping: :training

parameters:

  • attr_name : Attribute name to add in :hdata Hash

    as hdata[attr_name] = value.
  • options: Possible options:

    • :mapping : map name to use mapping instead of attr_name.

      hdata[map_name] = value
      
# File lib/core/definition.rb, line 452
def self.def_hdata(attr_name, options = {})
  PrcLib.model.heap true
  fct_context = { :function_name => __callee__ }
  return nil unless [String, Symbol, Array].include?(attr_name.class)

  options = {} unless options.is_a?(Hash)

  object_type = PrcLib.model.object_context(fct_context)

  key_access = KeyPath.new(attr_name).fpath

  # PrcLib.model.meta_obj://<Object>/:params/:keys/<keypath> must exist.
  object_param = PrcLib.model.meta_obj.rh_get(object_type,
                                              :params, :keys, key_access)

  object_param[:mapping] = attr_name
  object_param[:mapping] = options[:mapping] unless options[:mapping].nil?

  Lorj.debug(2, "%-28s: hdata set '%s' => '%s'",
             _object_name(object_type), attr_name, object_param[:mapping])

  # Internally, lorj stores this declaration in
  # PrcLib.model.meta_obj://<Object>/:params/:keys/<keypath>/:mapping)
end
def_query_attribute(key) click to toggle source

Application process to defines query attributes.

This function is depreciated.

def_attribute or def_attr_mapping already set the attribute as queriable. If the controller needs to redefine how the attribute is queried, use it will needs to call query_mapping.

But from process point of view, all attribute must be queriable.

So, use def_attribute(process), then query_mapping(controller)

# File lib/core/definition.rb, line 165
def self.def_query_attribute(key)
  PrcLib.model.heap true
  query_mapping(key, key)
end
define_data(data, options) click to toggle source

Process or controller to defines or update data model options Possible data model options are defined definition under <section>/<data> of defaults.yaml

Parameters:

  • data : String/Symbol. Name of the data

  • options : Hash. List of options

# File lib/core/definition.rb, line 279
def self.define_data(data, options)
  return nil unless [String, Symbol].include?(data.class)
  return nil if options.class != Hash
  PrcLib.model.heap true

  data = KeyPath.new data, 2
  PrcLib.dcl_fail("%s: Config data '%s' unknown",
                  self.class,
                  data) unless Lorj.data.auto_meta_exist?(data.key)

  PrcLib.model.data_context data

  section, key = Lorj.data.first_section(data.key)

  Lorj.data.define_controller_data(section, key, options)
end
define_obj(obj_type_name, handlers = nil) click to toggle source

Application process or controller to defines an object.

The context will be set by this definition for next declaration. Depending on the context, define_obj is not used identically:

Context : Application Process 'define_obj' is the first object declaration. It sets the object context for next declaration. At least it needs to create an handler or define it with :nohandler: true

Usually, this definition is followed by:

Context: Controller

A controller uses define_obj to update an existing object. A controller can create a new object, only if the controller defines specific process.

Usually, this definition is followed by:

  • query_mapping : Adapt query attribute to match controller query

    settings
    
  • obj_needs : Adapt needed parameters, and/or set mapping.

  • def_hdata : Define Controller Hash parameter, for handlers.

  • def_attr_mapping : Define object attribute mapping.

  • data_value_mapping: Define Data model values mapping.

  • Args

    • type : Symbol. Object type to declare.

    • handlers : Hash. List of Process handler to call for create/query/get/delete/update/get_attr. Handlers supported:

      • :create_e : Process function to call with create

      • :delete_e : Process function to call with delete

      • :update_e : Process function to call with update

      • :get_e : Process function to call with get

      • :query_e : Process function to call with query

      • :get_attr_e : Process function to call with get_attr

      • :refresh_e : Process function to call with refresh

# File lib/core/definition.rb, line 129
def self.define_obj(obj_type_name, handlers = nil)
  return nil unless [NilClass, String, Symbol].include?(obj_type_name.class)
  PrcLib.model.heap true

  obj_type_name = obj_type_name.to_sym if obj_type_name.is_a?(String)

  handlers = {} unless handlers.is_a?(Hash)

  lorj_object = PrcLib.model.meta_obj.rh_get(obj_type_name)

  # Checking handlers_options data
  _verify_handlers(obj_type_name, lorj_object, handlers)

  if lorj_object.nil?
    lorj_object = _define_obj_initialize(obj_type_name, handlers)
    PrcLib.model.meta_obj.rh_set(lorj_object, obj_type_name)
  end

  PrcLib.model.object_context(:object => obj_type_name)

  _handler_settings(lorj_object, handlers)

  nil
end
defined?(objType) click to toggle source
# File lib/core/definition.rb, line 317
def self.defined?(objType)
  PrcLib.model.heap true
  @obj_type.include?(objType)
end
new(oForjConfig, process, controller = nil) click to toggle source

Initialize Lorj BaseDefinition object

# File lib/core/lorj_basedefinition.rb, line 28
def initialize(oForjConfig, process, controller = nil)
  # Object Data object. Contains all loaded object data.
  # This object is used to build hParams as well.
  @object_data = ObjectData.new(true)
  #
  @runtime_context = {
    :oCurrentObj => nil
  }

  @config = oForjConfig

  @data = Lorj.data # Get data definition object
  # data object is currently built by
  # - global application defaults.yaml loaded in @config.
  # - process data.yaml files

  @erb_config = ERBConfig.new(oForjConfig)
  if !oForjConfig.is_a?(Lorj::Account) && !oForjConfig.is_a?(Lorj::Config)
    PrcLib.runtime_fail "'%s' is not a valid ForjAccount or ForjConfig"\
                       ' Object.', oForjConfig.class
  end
  @controller = controller
  unless controller.nil? || controller.is_a?(BaseController)
    PrcLib.runtime_fail "'%s' is not a valid BaseController Object type.",
                        controller.class
  end

  @process = process
  PrcLib.runtime_fail "'%s' is not a valid BaseProcess Object type.",
                      process.class unless process.is_a?(BaseProcess)

  @process.base_object = self
end
obj_needs(type, name, options = {}) click to toggle source

Function to declare handlers data/object needs. Used by application process declaration and controller declaration to defines the object data needs or sub-object dependency.

The application process declare global objects/data dependency while the controller can complete it with any needed other object/data as required by the controller code.

Ex: A process can define a generic connection object.

define_obj :connection
obj_needs :data, :user,   :for => [:create_e]
obj_needs :data, :passwd, :for => [:create_e]

The controller can add several other needs, specifically
to this controller.

define_obj :connection
obj_needs :data, :user,   mapping => :username
obj_needs :data, :uri

Requires Object context

parameters:

  • type : :data or :object requirement

  • name : Name of the data or the object.

  • options : Possible options

    • :for : Array: requirement for a limited list of handler.

      By default, all handlers requires this data or object.
# File lib/core/definition.rb, line 204
def self.obj_needs(type, name, options = {})
  return nil unless [String, Symbol].include?(type.class)
  return nil unless [String, Symbol, Array].include?(name.class)
  PrcLib.model.heap true

  type = type.to_sym if type.is_a?(String)

  options = {} unless options.is_a?(Hash)

  unless options.key?(:required)
    options[:required] = !PrcLib.model.needs_optional
  end

  _configure_options_handlers(options)

  params = PrcLib.model.meta_obj.rh_get(PrcLib.model.object_context,
                                        :params)

  _define_object_needs(params, type,
                       _initialize_object_needs(name), options)
end
obj_needs_optional() click to toggle source

Process declaration Set obj_needs requirement setting to false

# File lib/core/definition.rb, line 44
def self.obj_needs_optional
  PrcLib.model.heap true
  PrcLib.model.needs_optional true
end
obj_needs_requires() click to toggle source

Process declaration Set obj_needs requirement setting to True

# File lib/core/definition.rb, line 52
def self.obj_needs_requires
  PrcLib.model.heap true
  PrcLib.model.needs_optional false
end
predefine_data_value(data, hOptions) click to toggle source

Internal BaseDefinition function

# File lib/core/definition.rb, line 324
def self.predefine_data_value(data, hOptions)
  PrcLib.model.heap true
  # Refuse to run if not a
  return nil if self.class != BaseDefinition
  # BaseDefinition call
  return nil unless [String, Symbol].include?(value.class)
  return nil unless [NilClass, Symbol, String].include?(map.class)

  key_path = PrcLib.model.attribute_context

  value = { data => { :options => hOptions } }

  PrcLib.model.predefine_data_value.rh_set(value,
                                           key_path.fpath, :values)
end
process_default(hOptions) click to toggle source

Process declaration Defines default process options

parameters:

  • options : Supported options are:

    • use_controller : Boolean. True if the model require a controller

      False otherwise. Default is true.
# File lib/core/definition.rb, line 65
def self.process_default(hOptions)
  PrcLib.model.heap true
  supported_options = [:use_controller]
  unless hOptions.nil?
    hOptions.each_key do |key|
      case key
      when :use_controller
        value = hOptions.rh_get(:use_controller)
        next unless value.boolean?
        PrcLib.model[key] = hOptions[key]
      else
        PrcLib.dcl_fail("Unknown default process options '%s'. "\
                        "Supported are '%s'",
                        key, supported_options.join(','))
      end
    end
  end
end
query_mapping(key, map) click to toggle source

Controller declaration to map an query attribute By default, def_attribute configure those attributes as queriable. The controller can redefine the query part. Use def_attribute or def_attr_mapping All attributes are considered as queriable.

# File lib/core/definition.rb, line 357
def self.query_mapping(key, map)
  PrcLib.model.heap true
  _query_mapping(key, map)
end
undefine_attribute(key) click to toggle source

Process to undeclare default lorj object attributes By default, while process declares a new lorj object, :id and :name are predefined. If the model of this lorj object do not have any ID or Name the process will needs to undeclare it.

The Controller can undeclare some attribute defined by the Application process model. But it requires the controller to re-define any object handler which can use those attributes.

parameters:

  • key : Attribute name to undeclare.

# File lib/core/definition.rb, line 254
def self.undefine_attribute(key)
  return nil unless [String, Symbol].include?(key.class)
  PrcLib.model.heap true

  PrcLib.dcl_fail('%s: No Object defined. Missing define_obj?',
                  self.class) if PrcLib.model.object_context.nil?

  key_path = KeyPath.new(key)

  PrcLib.model.meta_obj.rh_set(nil, PrcLib.model.object_context,
                               :returns, key_path.fpath)
  PrcLib.model.attribute_context key_path
  Lorj.debug(4, "%s: Undefining attribute mapping '%s'",
             PrcLib.model.object_context, key_path.fpath)

  _query_mapping(key, nil)
end

Public Instance Methods

_ask(sDesc, default, rValidate, bEncrypted, bRequired) click to toggle source

internal runtime function for process call Ask function executed by setup

parameters:

- +sDesc+       : data description
- +default+     : default value
- +rValidate+   : RegEx to validate the end user input.
- +bEncrypted+  : Encrypt data
- +bRequired+   : true if a value is required.

return:

  • value : value or encrypted value.

raise:

# File lib/core/core_setup_ask.rb, line 310
def _ask(sDesc, default, rValidate, bEncrypted, bRequired)
  value = nil
  loop do
    if bEncrypted
      value = _ask_encrypted(sDesc, default)
    else
      value = ask(format('Enter %s:', sDesc)) do |q|
        q.default = default unless default.nil?
        q.validate = rValidate unless rValidate.nil?
      end
    end
    break unless bRequired && value == ''
    say ANSI.bold('This information is required!')
  end
  value.to_s
end
_nil_if_no_value(value) click to toggle source

Internal function to return nil if value is empty.

# File lib/core/core_setup_ask.rb, line 328
def _nil_if_no_value(value)
  return nil if value.nil? || value == ''
  value
end
_query_map(object_type, hParams) click to toggle source

Before doing a query, mapping fields Transform Object query field to Provider query Fields

# File lib/core/lorj_basedefinition.rb, line 103
def _query_map(object_type, hParams)
  return {} unless hParams

  object_type = object_type.to_sym if object_type.class == String

  result = {}
  maps = PrcLib.model.meta_obj.rh_get(object_type, :query_mapping)
  hParams.each do |key, value|
    key_path_obj = KeyPath.new(key)

    bold_action = ANSI.bold('ACTION REQUIRED')
    PrcLib.runtime_fail "Forj query field '%s.%s' not defined by class"\
                        " '%s'.\n#{bold_action}"\
                        ":\nMissing data model 'def_attribute' or "\
                        "'def_query_attribute' for '%s'??? "\
                        "Check the object '%s' data model.",
                        object_type, key_path_obj.key,
                        self.class, key_path_obj.key,
                        object_type unless maps.key?(key_path_obj.fpath)

    next if maps[key_path_obj.fpath].nil?

    map_path = KeyPath.new(maps[key_path_obj.fpath])
    _query_value_mapping(object_type, result, key_path_obj, map_path, value)
  end
  result
end
_query_value_mapping(object_type, result, key_path_obj, map_path, value) click to toggle source
# File lib/core/lorj_basedefinition.rb, line 131
def _query_value_mapping(object_type, result, key_path_obj, map_path, value)
  key_path = key_path_obj.fpath
  value_mapping = PrcLib.model.meta_obj.rh_get(object_type, :value_mapping,
                                               key_path)
  if value_mapping
    PrcLib.runtime_fail "'%s.%s': No value mapping for '%s'",
                        object_type, key_path_obj.key,
                        value unless value_mapping.rh_exist?(value)

    result.rh_set(value_mapping[value], map_path.to_s)
  else
    result.rh_set(value, map_path.to_s)
  end
  nil
end
_setup_ask(setup_steps) click to toggle source

internal setup core function which ask user to enter values. looping step by step and presenting sorted data to set.

It execute pre-process if defined by: /:section/<section name>/<data>/:pre_step_function

If pre-process returns true, end user interaction is canceled.

  • Args :

  • setup_steps : setup data structure.

  • Returns:

  • Raises :

# File lib/core/core_setup_init.rb, line 1076
def _setup_ask(setup_steps)
  # Ask for user input
  # TODO: Enhance to support section::data to avoid duplicated data name
  #   against sections.
  setup_steps.each_index do |iStep|
    _setup_display_step(setup_steps[iStep], iStep)

    order_array = setup_steps[iStep][:order]

    order_array.each_key do |iIndex|
      Lorj.debug(2, 'Ask order %s:', iIndex)
      order_array[iIndex].each do |data|
        options = _get_meta_data(data)
        options = {} if options.nil?

        Lorj.data.layer_add(:name => :setup)

        if options[:pre_step_function]
          proc = options[:pre_step_function]
          next unless @process.method(proc).call(data)
          # Get any update from pre_step_function
          options = _get_meta_data(data)
        end

        data_desc = _setup_display_data(data, options)

        _setup_ask_data(data_desc, data, options)

        Lorj.data.layer_remove(:name => :setup)
      end
    end
  end
end
_setup_ask_data(desc, data, options) click to toggle source

Internal setup function to ask to the end user. It execute post-process if defined by: /:section/<section name>/<data>/:post_step_function

if post-process returns false, the user is requested to re-enter a new value

  • Args :

    • desc : Data description

    • data : Data to ask.

    • options: list and validation options

      • :post_step_function : Call a post process function.

  • Returns:

    • nothing

  • Raises :

# File lib/core/core_setup_ask.rb, line 47
def _setup_ask_data(desc, data, options)
  loop do
    if options[:list_values].nil?
      value = _setup_ask_data_from_keyboard(desc, data, options)
    else
      value = _setup_ask_data_from_list(data, options[:list_values],
                                        desc, options)
    end

    # @config.set(data, value) ??? Why do we need that???
    section = _get_account_section(data)
    # We set the value only if there is a value entered by the user.
    unless section.nil? || value.nil?
      Lorj.debug(3, "'%s'/'%s': Setting value to '%s'",
                 section, data, value)
      @config.set(data, value, :name => 'account', :section => section)
    end

    result = _setup_ask_post_process(options[:post_step_function])
    break unless result.is_a?(FalseClass)
  end
end
_setup_ask_data_from_keyboard(desc, data, options, default = nil) click to toggle source

Internal setup function to ask to the end user.

  • Args :

    • desc : Data description

    • data : Data to ask.

    • options: list and validation options

      • :ask_function : Replace the _ask default call by a process function This function should return a string or nil, if no value.

      • :default_value: Predefined default value.

    • default: Default value.

      setup will present a default value. This value can come from several places, as follow in that order:

      1. if a value is found from config layers => choose it as default

      2. if default parameter is not nil => choose it as default

      3. if data model defines :default_value. => choose it

      In this last case, the :default_value is interpreted by ERB.
      ERB context contains:
      - config : data config layer.
      
      Ex: So you can set :default_value like:
      
           :default_value: "~/.ssh/<%= config[:keypair_name] %>-id_rsa"
      This may assume that keypair_name is setup before abd would need:
      - :after: <datas>
  • Returns:

    • value : value entered by the end user or nil if no value.

  • Raises :

# File lib/core/core_setup_ask.rb, line 261
def _setup_ask_data_from_keyboard(desc, data, options, default = nil)
  valid_regex = nil
  valid_regex = options[:validate] unless options[:validate].nil?

  is_required = (options[:required] == true)
  is_encrypted = options[:encrypted]

  if default.nil? && !options[:default_value].nil?
    begin
      default = erb(options[:default_value])
      Lorj.debug(3, "'%s': Running ERB for default_value '%s' = '%s'",
                 data, options[:default_value], default)
    rescue => e
      PrcLib.warning("ERB error with :%s/:default_value '%s'.\n%s",
                     data, options[:default_value], e.message)
    end
  end
  ask_default = @config.get(data, default)
  Lorj.debug(3, "'%s': Getting value from config - '%s'(from '%s' - "\
                "sections '%s') (default is '%s')",
             data, ask_default, @config.where?(data),
             Lorj.data.sections(data), default)

  # validate_proc = options[:validate_function]
  proc_ask = options[:ask_function]

  if proc_ask.nil?
    value = _ask(desc, ask_default, valid_regex, is_encrypted, is_required)
  else
    value = @process.method(proc_ask)
  end
  _nil_if_no_value(value)
end
_setup_ask_data_from_list(data, list_options, desc, options) click to toggle source

Internal setup function to ask to the end user from a list.

  • Args :

  • data : Data to ask.

  • list_options: list and validation options

    • :validate : Can be :list_strict to restrict possible value to only those listed.

  • desc : Data description

  • options : Used when user have to enter a string instead of

    selecting from a list.
    • :default_value : predefined default value.

    if data model defines :default_value. => choose it
    In this last case, the :default_value is interpreted by ERB.
    ERB context contains:
      - config : data config layer.
    
      Ex: So you can set :default_value like:
    
           :default_value: "~/.ssh/<%= config[:keypair_name] %>-id_rsa"
      This may assume that keypair_name is setup before abd would need:
      - :after: <datas>
  • Returns:

    • value : value entered by the end user.

  • Raises :

# File lib/core/core_setup_ask.rb, line 153
def _setup_ask_data_from_list(data, list_options, desc, options)
  obj_to_load = list_options[:object]

  result = _setup_choose_list_process(obj_to_load, list_options,
                                      options[:default_value])

  list = result[:list]
  default = options[:default_value]
  default = result[:default_value] unless result[:default_value].nil?

  begin
    Lorj.debug(3, "'%s': ERB on default value '%s'", data, default)
    default = erb(default) unless default.nil?
  rescue => e
    PrcLib.warning("ERB error with :%s/:default_value '%s'.\n%s",
                   data, result[:default_value], e.message)
  else
    default = nil if default == ''
    Lorj.debug(3, "'%s': default value '%s'", data, default)
    options[:default_value] = default
  end

  is_strict_list = (list_options[:validate] == :list_strict)

  if list.nil?
    list = []

    if is_strict_list
      PrcLib.fatal(1, "%s requires a value from the '%s' query which is "\
                  'empty.', data, obj_to_load)
    else
      list << 'Not in this list'
    end
  end

  value = _setup_choose_data_from_list(data, desc, list, options)

  if !is_strict_list && value == 'Not in this list'
    value = _setup_ask_data_from_keyboard(desc, data, options)
  end
  value
end
_setup_ask_post_process(proc) click to toggle source

Execute the post process on data entered by the user

  • returns

    • false if the process ask the user to re-enter a value.

    • true otherwise.

# File lib/core/core_setup_ask.rb, line 75
def _setup_ask_post_process(proc)
  return true if proc.nil?

  result = @process.method(proc).call

  unless result.boolean?
    PrcLib.debug("Warning: '%s' did not return any boolean"\
                 ' value. Ignored', proc)
    result = true
  end
  result
end
_setup_attrs_depends_on(dependencies, attr_name, attrs) click to toggle source

Internal setup function - Identify a list of attributes from depends_on

If the attribute has a object dependency, attributes attached are added. If the object has depends_on

# File lib/core/core_setup_init.rb, line 933
def _setup_attrs_depends_on(dependencies, attr_name, attrs)
  return [] unless attrs.is_a?(Array) && attrs.length > 0

  result = []

  Lorj.debug(3, "%s: depends on added '%s'", attr_name, attrs.join(', '))

  attrs.each do |a|
    data = Lorj.data.auto_section_data(a)

    if data.rh_exist?(:list_values, :object)
      element = _setup_bs_objs_deps(dependencies,
                                    data.rh_get(:list_values, :object))
      element[:attrs] += dependencies.rh_get(:object, element[:obj], :attrs)
    else
      element = { :attrs => [] }
    end

    if data[:depends_on].is_a?(Array)
      element[:depends_on] = _setup_attrs_depends_on(dependencies, a,
                                                     data[:depends_on])
    else
      element[:depends_on] = []
    end

    attrs_list = element[:attrs] + element[:depends_on]
    attrs_list.uniq!
    result += attrs_list
  end
  result.uniq
end
_setup_bs_levels(attrs, level) click to toggle source

Uses attributes level detected to initialize the list of steps/orders.

# File lib/core/core_setup_init.rb, line 652
def _setup_bs_levels(attrs, level)
  steps = [[]]
  pos = 0

  loop do
    attrs.clone.each do |k, v|
      cur_level = v.rh_get(:group, :level)
      next unless cur_level == level

      attrs_to_add = v[:attrs] + v.rh_get(:group, :attrs).uniq
      attrs.reject! do |attr, _|
        res = attrs_to_add.include?(attr)
        steps[pos] << { attr => attrs[attr] } if res
        res
      end

      steps[pos + 1] = [] if steps[pos + 1].nil?

      steps[pos + 1] << { k => attrs[k] }
      attrs.reject! { |attr, _| attr == k }
    end
    level += 1
    break if level == 0
    pos += 1
  end
  steps
end
_setup_bs_list_query(dependencies, attr_name, data, element) click to toggle source
# File lib/core/core_setup_init.rb, line 775
def _setup_bs_list_query(dependencies, attr_name, data, element)
  return unless data.rh_exist?(:list_values, :object)

  element[:obj] = data.rh_get(:list_values, :object)
  element[:group] = _setup_bs_objs_deps(dependencies, element[:obj])

  _object_params_event(element[:obj], :query_e, :data).each do |attr_obj|
    element[:attrs] << attr_obj.key_tree
  end
  Lorj.debug(5, "attr setup '%s': query '%s' (+ %s) and "\
                "requires '%s' (+ %s)", attr_name,
             element[:obj], element[:group][:objs],
             element[:attrs], element[:group][:attrs] - element[:attrs])
end
_setup_bs_objs(attrs_done, dependencies, attr_name) click to toggle source

Internal setup function to build the list of attribute deps

# File lib/core/core_setup_init.rb, line 682
def _setup_bs_objs(attrs_done, dependencies, attr_name)
  # Check if this attr requires an object query.
  Lorj.debug(2, "-- Checking '%s' attribute --", attr_name)
  data = Lorj.data.auto_section_data(attr_name)

  element = _setup_bs_objs_init(data)

  return element if data.nil?

  return element unless data.rh_exist?(:list_values, :object) ||
                        data[:depends_on].is_a?(Array)

  _setup_bs_list_query(dependencies, attr_name, data, element)

  # ensure attribute dependency is dynamically added to the list of
  # object deps.
  _setup_bs_objs_new_dep(dependencies, attr_name, element)

  element[:depends_on] = []
  element[:depends_on] = data[:depends_on] if data[:depends_on].is_a?(Array)

  group = element[:group]
  if group[:objs].length > 0
    _setup_set_group_level(dependencies, attrs_done, attr_name,
                           group, group[:objs].sort)
  else
    _setup_set_group_level(dependencies, attrs_done, attr_name,
                           group, [element[:obj]])
  end

  _setup_attrs_depends_on(dependencies, attr_name,
                          element[:depends_on])

  element
end
_setup_bs_objs_deps(dependencies, object_type) click to toggle source

Internal setup function - Extract object data information.

# File lib/core/core_setup_init.rb, line 898
def _setup_bs_objs_deps(dependencies, object_type)
  group = { :objs => nil, :attrs => nil }
  if dependencies.rh_exist?(:objects, object_type)
    group[:objs], group[:attrs] = _setup_objects_attr_needs(dependencies,
                                                            object_type)
    return group
  end
  _setup_identify_dep_init(dependencies, object_type)
  group[:objs], _, group[:attrs] = _setup_identify_deps(dependencies,
                                                        object_type)
  group
end
_setup_bs_objs_init(data) click to toggle source

Initialize attribute element.

# File lib/core/core_setup_init.rb, line 719
def _setup_bs_objs_init(data)
  element = { :obj => nil, :setup => false, :ask_sort => nil,
              :group => { :objs => [], :attrs => [] },
              :attrs => [], :ask_step => nil }

  return element if data.nil?

  element[:setup] = data[:account] if data.rh_get(:account).boolean?
  if data.rh_get(:ask_sort).is_a?(Fixnum)
    element[:ask_sort] = data[:ask_sort]
  end

  element[:ask_step] = data[:ask_step]

  element
end
_setup_bs_objs_new_dep(dependencies, parent_attr_name, element) click to toggle source

Internal function to verify if any attributes adds an object dependency

# File lib/core/core_setup_init.rb, line 738
def _setup_bs_objs_new_dep(dependencies, parent_attr_name, element)
  attrs = (element[:attrs] + element[:group][:attrs]).uniq
  return if attrs.length == 0

  found = false

  attrs.each do |attr_name|
    obj_found = dependencies.rh_get(:attributes, attr_name, :obj)
    next if obj_found.nil?

    objs = element.rh_get(:group, :objs)
    next if objs.include?(obj_found)

    dep = dependencies.rh_get(:attributes, attr_name)
    # Updating list of deps objs
    objs << obj_found
    objs = (objs + dep[:group][:objs]).uniq
    element.rh_set(objs, :group, :objs)

    # Undating list of deps attributes
    attrs = element.rh_get(:group, :attrs)
    attrs_found = (attrs + dep[:attrs] + dep[:group][:attrs]).uniq
    element.rh_set(attrs_found, :group, :attrs)

    Lorj.debug(4, "attr setup '%s': '%s' dependent attribute adds a new"\
                  " object dependency '%s'",
               parent_attr_name, attr_name, obj_found)
    found = true
  end
  return unless found

  Lorj.debug(5, "attr setup '%s': query '%s' (+ %s) and "\
                "requires '%s' (+ %s)", parent_attr_name,
             element[:obj], element[:group][:objs],
             element[:attrs], element[:group][:attrs] - element[:attrs])
end
_setup_build_process_params(option_params, params) click to toggle source
# File lib/core/core_setup_list.rb, line 96
def _setup_build_process_params(option_params, params)
  return if option_params.nil?

  option_params.each do |key, value|
    next if value.nil?
    begin
      value = erb(value)
    rescue => e
      Prclib.warning("ERB:process parameter failed to set '%s' with '%s'."\
                     "\n%s", key, value, e.message)
    end
    params << { key => value }
  end
end
_setup_build_steps_from(dependencies) click to toggle source

Internal setup function to complete the list of attributes and organize attributes by step as requested by attr dependencies It loops on a list of unanalyzed attributes to determine new objects/attributes

The analyze is based on attributes having setup obj (and group of deps) required

A new level is added:

  • when a new group of deps is found. Then each attributes required decrease the level by 1.

  • when a group already exist, nothing is done

In case of depends_on, the attribute level is set to 0 and depends_on attributes level are decreased. each attributes parsed get a level 0 if requires a group is requires otherwise level is set to nil.

# File lib/core/core_setup_init.rb, line 618
def _setup_build_steps_from(dependencies)
  count = dependencies[:attributes].length
  attrs_done = {}
  level = 0
  loop do
    attrs = dependencies[:attributes].clone
    attrs.each_key do |attr_name|
      next if attrs_done.key?(attr_name)

      element = _setup_bs_objs(attrs_done, dependencies, attr_name)

      attrs_done[attr_name] = element
      dependencies.rh_set(element, :attributes, attr_name)

      if element.rh_exist?(:group, :level)
        level = [level, element[:group][:level]].min
      end

      list_attrs = (element[:attrs] + element.rh_get(:group, :attrs)).uniq

      next if list_attrs.length == 0
      Lorj.debug(2, "setup: '%s' attribute dependency found '%s'",
                 attr_name, list_attrs.join(', '))
    end
    break if dependencies[:attributes].length == count
    count = dependencies[:attributes].length
  end

  # Thanks to attributes/group deps, set levels
  attrs = dependencies[:attributes]
  _setup_bs_levels(attrs, level)
end
_setup_check_additional(setup_steps) click to toggle source

check for any additional data to ask to the user thanks to the /:setup/:ask_step/<steps>/:add option of each steps

  • Args :

    • setup_steps : Hash. setup data structure to update.

      It will update setup_steps:/:order 2 dimensions array
  • Returns:

  • Raises :

# File lib/core/core_setup_init.rb, line 112
def _setup_check_additional(setup_steps)
  setup_steps.each do |step|
    step_name = step[:name]
    value = _setup_step_definition
    next unless value.is_a?(Hash) && value.rh_exist?(step_name, :add)

    datas_to_add = value.rh_get(step_name, :add)
    datas_to_add.each do |data_to_add|
      order_array = step[:order]
      next if _setup_attr_already_added?(order_array, data_to_add)

      _setup_data_insert(step, data_to_add)
    end
  end
end
_setup_choose_data_from_list(data, desc, list, options) click to toggle source

Internal setup function to present the list to the user and ask to choose.

  • Args :

  • data : Data to ask.

  • desc : Data description

  • list : list of values to choose

  • options : Used when user have to enter a string instead of

    selecting from a list.
  • Returns:

    • value : value entered by the end user.

  • Raises :

# File lib/core/core_setup_ask.rb, line 212
def _setup_choose_data_from_list(data, desc, list, options)
  default = @config.get(data, options[:default_value])
  Lorj.debug(3, "'%s': Getting value from config - '%s'(from '%s' - "\
                "sections '%s')"\
                " (default is '%s')",
             data, default, @config.where?(data), Lorj.data.sections(data),
             options[:default_value])

  say_msg = format("Select '%s' from the list:", desc)
  say_msg += format(' |%s|', default) unless default.nil?
  say(say_msg)
  value = choose do |q|
    q.choices(*list)
    q.default = default if default
  end
  value
end
_setup_choose_list_process(obj_to_load, list_options, default_value = nil) click to toggle source

Internal setup function to ask to the end user from a list.

  • Args :

  • obj_to_load : Object to get list from.

  • list_options: list and validation options

  • Returns:

    • Hash : list of possible values and default. :default_value : Value pre-selected. :list : list of possible values

  • Raises :

# File lib/core/core_setup_ask.rb, line 101
def _setup_choose_list_process(obj_to_load, list_options,
                               default_value = nil)
  result = { :list => [], :default_value => nil }
  case list_options[:query_type]
  when :controller_call
    result = _setup_list_from_controller_call(obj_to_load, list_options,
                                              default_value)
  when :query_call
    result = _setup_list_from_query_call(obj_to_load, list_options,
                                         default_value)
  when :process_call
    result = _setup_list_from_process_call(obj_to_load, list_options,
                                           default_value)
  else
    PrcLib.runtime_fail "%s: '%s' invalid query type. valid is: '%s'.",
                        obj_to_load, list_options[:values_type],
                        [:controller_call, :query_call, :process_call]
  end
  result
end
_setup_display_data(data, options) click to toggle source

internal setup function to display step information

  • Args :

  • data : data name to ask.

  • options : data options

  • Returns:

  • desc : Description of the data to ask.

  • Raises :

# File lib/core/core_setup_init.rb, line 1039
def _setup_display_data(data, options)
  desc = format("'%s' value", data)

  unless options[:explanation].nil?
    begin
      puts format('%s: %s',
                  data,
                  erb(options[:explanation]))
    rescue => e
      PrcLib.error "setup key '%s/:explanation' : %s", data, e.message
    end
  end

  begin
    desc = erb(options[:desc]) unless options[:desc].nil?
  rescue => e
    PrcLib.error "setup key '%s/:desc' : %s", data, e.message
  end

  desc
end
_setup_display_step(setup_step, step) click to toggle source
case attr_type
when :data
  return unless _setup_obj_param_is_data(setup_steps,
                                         inspected_objects, attr_name)
  inspected_objects << attr_name
  return
when :CloudObject
  return if objs_to_inspect.include?(attr_name) ||
            inspected_objects.include?(attr_name)
  # New object to inspect
  objs_to_inspect << attr_name
end

end

# File lib/core/core_setup_init.rb, line 1015
def _setup_display_step(setup_step, step)
  Lorj.debug(2, 'Ask step %s:', step)
  puts ANSI.bold(setup_step[:desc]) unless setup_step[:desc].nil?
  begin
    erb_msg = ANSI.yellow(
      erb(setup_step[:explanation])
    ) unless setup_step[:explanation].nil?
  rescue => e
    PrcLib.error "setup step '%d/:explanation' : %s", step, e.message
  end
  puts format("%s\n\n", erb_msg) unless erb_msg.nil?
end
_setup_id_each(dependencies, model_object, new_path, attr_path, attr_params) click to toggle source
# File lib/core/core_setup_init.rb, line 233
def _setup_id_each(dependencies, model_object, new_path,
                   attr_path, attr_params)
  objects = []
  attrs = []
  deps_attrs = []
  deps_objects = []

  attr_name = KeyPath.new(attr_path).key_tree
  attr_type = attr_params[:type]

  case attr_type
  when :data
    attr_to_add = _setup_id_init_data_deps(dependencies, attr_name)
    if attr_to_add
      model_object[:attrs] << attr_to_add
      attrs << attr_to_add
    end
  when :CloudObject
    if _setup_identify_dep_init(dependencies, attr_name, new_path)
      found_obj,
        found_attrs,
        found_deps_attrs = _setup_identify_deps(dependencies,
                                                attr_name, new_path)
    else
      found_obj = dependencies.rh_get(:objects, attr_name, :objects)
      found_attrs = dependencies.rh_get(:objects, attr_name, :attrs)
      found_deps_attrs = []
    end
    deps_objects = (deps_objects + found_obj).uniq
    deps_attrs = (deps_attrs + found_attrs + found_deps_attrs).uniq
    model_object[:objects] << attr_name
    objects << attr_name
  end
  [attrs, deps_attrs, objects, deps_objects]
end
_setup_id_init_data_deps(dependencies, attr_name) click to toggle source
# File lib/core/core_setup_init.rb, line 269
def _setup_id_init_data_deps(dependencies, attr_name)
  return if dependencies[:attributes].key?(attr_name)

  dependencies.rh_set({}, :attributes, attr_name)
  attr_name
end
_setup_identify(sObjectType, setup_steps) click to toggle source

Function to build a step/order structure of Attributes. step/order is an array of array. the first array represents the steps the second array represents the list of attributes in a specific order.

This structure is used by setup to ask the list of attributes in a specific order.

It loops on object dependencies, then data definition to determine the list of attributes and their required order.

A new step is created when an attribute, during setup time requires to query an object, which may requires some additional attributes, considered as dependent attributes. The previous step must contains at least the dependent attributes.

Process data definition can influence those detected steps, by assigning an :ask_step to the attribute. Then the default attribute step may be splitted to more steps.

You cannot set an attribute step lower then the detected step. Process data definition can influence the attributes order, by assigning an :ask_order to the attribute.

:setup section of the process data definition (data.yaml) can set the step description or add some extra attributes (not detected by default)

  • Args :

    • sObjectType : Symbol/String. Object type to analyze for list of attributes to setup

    • setup_steps : Hash. setup data structure to update.

      It will update setup_steps:/:order 2 dimensions array
  • Returns:

    • setup_steps: Hash updated

  • Raises :

# File lib/core/core_setup_init.rb, line 166
def _setup_identify(sObjectType, setup_steps)
  # There is 3 sources of data used by setup to build the list of data to
  # setup:
  # - Lorj.data (Lorj::MetaConfig): Process data definition.
  # - config (Lorj::Account)      : Configuration files/runtime data.
  # - PrcLib.model.meta_obj(Hash) : Object definition / mapping

  dependencies = { :objects => {}, :attributes => {} }
  _setup_identify_dep_init(dependencies, sObjectType)

  # Build list of attributes which will be needed for an object and
  # its dependencies

  Lorj.debug(2, '- Checking objects dependencies -')
  _setup_identify_deps(dependencies, sObjectType)

  # Build list of additional attributes and build
  # attribute dependencies thanks to attribute queries.
  Lorj.debug(2, '- Checking attributes dependencies -')
  orders = _setup_build_steps_from(dependencies)

  # Reorganize each required steps thanks to :ask_order
  Lorj.debug(2, '- Re-organizing attributes steps/order -')
  attrs = _setup_reorganize_steps_order(dependencies[:attributes], orders)

  # Apply additionnal steps as described by Lorj.data
  Lorj.debug(2, '- Add extra steps -')
  _setup_reorganize_steps(attrs, orders, setup_steps)
end
_setup_identify_dep_init(dependencies, object_type, path = []) click to toggle source

Internal setup function initializing a model object

# File lib/core/core_setup_init.rb, line 977
def _setup_identify_dep_init(dependencies, object_type, path = [])
  if path.include?(object_type)
    PrcLib.warning('Loop detection: Be careful! a loop is detected with'\
                   " the dependency from '%s' to '%s'. "\
                   'Dependency ignored.', path.join('/'), object_type)
    return false
  end

  return false if dependencies.rh_exist?(:objects, object_type)

  model_object = { :objects => [], :objects_attrs => [], :attrs => [] }

  dependencies.rh_set(model_object, :objects, object_type)
  true
end
_setup_identify_deps(dependencies, object_type, path = []) click to toggle source

Internal setup function to parse objects/attributes dependency list and build objects list and required attributes list.

# File lib/core/core_setup_init.rb, line 198
def _setup_identify_deps(dependencies, object_type, path = [])
  model_object = dependencies.rh_get(:objects, object_type)
  objects_list = PrcLib.model.meta_obj.rh_get(object_type, :params, :keys)
  if objects_list.nil?
    PrcLib.warning("'%s' as object type is not valid. Not declared.")
    return [[], [], []]
  end

  objects = []
  attrs = []
  deps_attrs = []
  deps_objects = []
  new_path = path + [object_type]

  objects_list.each do |attr_path, attr_params|
    a, d_a, o, d_o = _setup_id_each(dependencies, model_object, new_path,
                                    attr_path, attr_params)
    attrs += a
    deps_attrs += d_a
    objects += o
    deps_objects += d_o
  end
  attrs.uniq!
  deps_attrs.uniq!
  objects.uniq!
  deps_objects.uniq!

  _sid_show_debug(3, format("'%s' has ", object_type) + '%s',
                  attrs, objects)
  _sid_show_debug(4, format("'%s' has ", object_type) + 'also indirect %s',
                  deps_attrs, deps_objects)

  [(objects + deps_objects).uniq, attrs, deps_attrs]
end
_setup_list_from_controller_call(obj_to_load, list_options, default) click to toggle source

Internal setup function to build the list from a controller call.

  • Args :

  • obj_to_load : Object to get list from.

  • list_options: list and validation options

  • Returns:

    • Hash : list of possible values and default. :default_value : Value pre-selected. :list : list of possible values

  • Raises :

# File lib/core/core_setup_list.rb, line 42
def _setup_list_from_controller_call(obj_to_load, list_options, default)
  PrcLib.message("Loading :object #{obj_to_load}.")
  Lorj.debug(3, ':query_type = :controller_call')

  object = @object_data[obj_to_load, :ObjectData]
  object = process_create(obj_to_load) if object.nil?
  return nil if object.nil?

  params = ObjectData.new
  params.add(object)
  params << list_options[:query_params]

  PrcLib.runtime_fail '%s: query_type => :controller_call '\
               'requires missing :query_call declaration'\
               ' (Controller function)',
                      data if list_options[:query_call].nil?

  proc = list_options[:query_call]
  begin
    list = @controller.method(proc).call(obj_to_load, params)
  rescue => e
    PrcLib.runtime_fail "Error during call of '%s':\n%s", proc, e.message
  end
  { :list => list, :default_value => default }
end
_setup_list_from_process_call(obj_to_load, list_options, default) click to toggle source

Internal setup function to build the list from a process call.

  • Args :

  • obj_to_load : Object to get list from.

  • list_options: list and validation options

  • Returns:

    • Hash : list of possible values and default. :default_value : Value pre-selected. :list : list of possible values

  • Raises :

# File lib/core/core_setup_list.rb, line 124
def _setup_list_from_process_call(obj_to_load, list_options, default)
  PrcLib.runtime_fail '%s: query_type => :process_call'\
               ' requires missing :query_call declaration'\
               ' (Provider function)',
                      data if list_options[:query_call].nil?
  proc = list_options[:query_call]
  obj_to_load = list_options[:object]
  PrcLib.message("Running process '#{proc}' on :object '#{obj_to_load}'.")
  Lorj.debug(3, ':query_type = :process_call')

  # Building Process function attr_params parameter
  params = ObjectData.new

  params << { :default_value => default }

  _setup_build_process_params(list_options[:query_params], params)

  begin
    proc_method = @process.method(proc)
    result = proc_method.call(obj_to_load, params)
  rescue => e
    PrcLib.runtime_fail "Error during call of '%s':\n%s",
                        proc, e.message
  end

  if result.is_a?(Hash)
    if result[:list].nil? ||
       !result[:list].is_a?(Array)
      PrcLib.debug("Process function '%s' did not return an"\
                   ' :list => Array of list_options.',
                   list_options[:query_call])
    end
  else
    PrcLib.debug("Process function '%s' did not return an"\
                 ' Hash with :list and :default_value')
    result = { :list => [], :default_value => nil }
  end
  result
end
_setup_list_from_query_call(obj_to_load, list_options, default) click to toggle source

Internal setup function to build the list from a query call.

  • Args :

  • obj_to_load : Object to get list from.

  • list_options: list and validation options

  • Returns:

    • Hash : list of possible values and default. :default_value : Value pre-selected. :list : list of possible values

  • Raises :

# File lib/core/core_setup_list.rb, line 81
def _setup_list_from_query_call(obj_to_load, list_options, default)
  PrcLib.message("Querying :object #{obj_to_load}.")
  Lorj.debug(3, ':query_type = :query_call - ')

  query_hash = list_options[:query_params]
  query_hash = {} if query_hash.nil?

  object_list = process_query(obj_to_load, query_hash)

  list = []
  object_list.each { |oElem| list << oElem[list_options[:value]] }

  { :list => list.sort!, :default_value => default }
end
_setup_load() click to toggle source

Load /:setup/:ask_step section of the data.yaml

See lib/core/core_model.rb

  • Returns:

    • hash : setup data structure.

  • Raises :

# File lib/core/core_setup_init.rb, line 39
def _setup_load
  setup_steps = {}

  steps = Lorj.data.setup_data(:steps)
  return setup_steps if steps.nil?

  steps.each do |name, value|
    setup_steps[name] = _setup_load_init(value)
  end

  ask_steps = Lorj.data.setup_data(:ask_step)
  return setup_steps if ask_steps.nil?

  ask_steps.each do |value|
    name = value[:name]
    name = ask_steps.index(value).to_s if name.nil?
    if setup_steps.key?(name)
      setup_steps[name].rh_merge(_setup_load_init(value))
      next
    end
    setup_steps[name] = _setup_load_init(value)
  end

  setup_steps
end
_setup_load_init(value) click to toggle source
# File lib/core/core_setup_init.rb, line 65
def _setup_load_init(value)
  value = {} if value.nil?

  {
    :desc => value[:desc],
    :explanation => value[:explanation],
    :pre_step_handler => value[:pre_step_function],
    :order => [[]], # attributes in array of level/order
    :post_step_handler => value[:post_step_function]
  }
end
_setup_objects_attr_needs(dependencies, object_type) click to toggle source

Internal setup function - Build list of ALL attributes required for an object

It navigates on loaded dependencies to build the list of attributes.

# File lib/core/core_setup_init.rb, line 915
def _setup_objects_attr_needs(dependencies, object_type)
  attrs = []

  objects = dependencies.rh_get(:objects, object_type, :objects)
  deps_objects = []
  objects.each do |o|
    attrs += dependencies.rh_get(:objects, o, :attrs)
    found_obj, deps_attrs = _setup_objects_attr_needs(dependencies, o)
    attrs += deps_attrs
    deps_objects += found_obj
  end
  [(objects + deps_objects).uniq, attrs.uniq]
end
_setup_reorganize_so_befaft(attr_group) click to toggle source

Internal setup function to re-organize thanks to :before and :after.

# File lib/core/core_setup_init.rb, line 346
def _setup_reorganize_so_befaft(attr_group)
  attrs = attr_group.map { |a| a.keys[0] }

  attrs.clone.each do |attr_name|
    meta = _get_meta_data(attr_name)
    next if meta.nil?
    next unless meta.rh_exist?(:after) || meta.rh_exist?(:before)

    if _setup_reorganize_so_befaft_move?(:after, meta, attrs, attr_name)
      _setup_reorganize_so_befaft_move(:after, meta, attrs, attr_group,
                                       attr_name)
    end

    next unless _setup_reorganize_so_befaft_move?(:before, meta, attrs,
                                                  attr_name)

    _setup_reorganize_so_befaft_move(:before, meta, attrs, attr_group,
                                     attr_name)
  end
  attr_group
end
_setup_reorganize_so_befaft_move(where, meta, attrs, attr_group, attr_name) click to toggle source

Do the move

# File lib/core/core_setup_init.rb, line 379
def _setup_reorganize_so_befaft_move(where, meta, attrs, attr_group,
                                     attr_name)
  old = attrs.index(attr_name)
  ref = meta[where]
  new = attrs.index(ref)

  # Must be inserted after the attribute => + 1
  new += 1 if where == :after

  Lorj.debug(5, ":%s: Move '%s' %s '%s'"\
                    " - pos '%s' => pos '%s'",
             where, attr_name, where, ref, old, new)

  attrs.insert(new, attrs.delete(attr_name))
  attr_group.insert(new, attr_group.delete(attr_group[old]))
end
_setup_reorganize_so_befaft_move?(where, meta, attrs, attr_name) click to toggle source

return true if there is a need to move the element before/after

# File lib/core/core_setup_init.rb, line 369
def _setup_reorganize_so_befaft_move?(where, meta, attrs, attr_name)
  element = meta[where]
  element = nil unless (attrs - [attr_name]).include?(element)

  cur = attrs.index(attr_name)
  return (element && cur < attrs.index(element)) if where == :after
  (element && cur > attrs.index(element))
end
_setup_reorganize_so_sort(attr_group) click to toggle source

Internal setup function to re-organize thanks to :ask_sort

# File lib/core/core_setup_init.rb, line 397
def _setup_reorganize_so_sort(attr_group)
  attr_subgroups = []
  attr_noorder = []

  attr_group.each do |attr|
    attr_def = attr[attr.keys[0]]
    if attr_def[:ask_sort].is_a?(Fixnum)
      Lorj.debug(4, "'%s' position requested is '%s'",
                 attr.key(attr_def), attr_def[:ask_sort])
      if attr_subgroups[attr_def[:ask_sort]].nil?
        attr_subgroups[attr_def[:ask_sort]] = [attr]
      else
        attr_subgroups[attr_def[:ask_sort]] << attr
      end
    else
      attr_noorder << attr
    end
  end

  attr_subgroups.flatten!

  attr_subgroups + attr_noorder
end
_setup_reorganize_steps(steps_unordered, steps, setup_steps) click to toggle source

Internal setup function to re-organize steps as described by :setup/:steps section and data property :step

# File lib/core/core_setup_init.rb, line 424
def _setup_reorganize_steps(steps_unordered, steps, setup_steps)
  steps << steps_unordered

  # build the steps attributes
  build_steps = [{ :order => {} }]
  build_step = 0
  step_name = nil
  #  cur_step = build_steps[build_step]
  Lorj.debug(3, "Building setup step position '%s'", build_step)

  steps.each_index do |step_index|
    steps[step_index].each do |attr|
      attr_name = attr.keys[0]
      attr_def = attr[attr_name]

      unless attr_def[:setup]
        Lorj.debug(2, "'%s' is ignored. configured with :account = '%s'",
                   attr_name, attr_def[:setup])
        next
      end

      step_name = _setup_ros_get_step_name(attr_def)

      next if _setup_ros_same_step_name(build_steps[build_step],
                                        step_index, step_name, attr_name)

      build_step = _setup_ros_set_step(:build_steps => build_steps,
                                       :build_step => build_step,
                                       :setup_steps => setup_steps,
                                       :step_index => step_index,
                                       :step_name => step_name,
                                       :attr_name => attr_name)

      _setup_ros_add_attribute(build_steps[build_step][:order],
                               step_index, attr_name)
    end
  end

  if build_steps.last[:name].nil?
    _setup_ros_set_step(:build_steps => build_steps,
                        :setup_steps => setup_steps,
                        :step_index => steps.length - 1,
                        :attr_name => :default)
  end

  build_steps
end
_setup_reorganize_steps_order(attrs, attr_groups) click to toggle source

Internal setup function to Reorganize attributes order thanks following data definition:

  • :sections/<Section>/<Attribute>/:ask_sort: (FixNum) Defines the list of attributes that needs to be setup before.

This function will first of all determine the order thanks to :ask_sort in the current step group.

# File lib/core/core_setup_init.rb, line 317
def _setup_reorganize_steps_order(attrs, attr_groups)
  attr_groups.collect do |attr_group|
    index = attr_groups.index(attr_group)
    Lorj.debug(3, "Step '%s' analyzing re-organisation", index)
    res = _setup_reorganize_so_sort(attr_group)
    res = _setup_reorganize_so_befaft(res)

    old = attr_group.map { |attr| attr.keys[0] }
    new = res.map { |attr| attr.keys[0] }
    Lorj.debug(3, "Step '%s' reorganized from '%s' to '%s'",
               index, old, new) unless old == new
    attr_groups[index] = res
  end

  attrs_list = []
  attrs.each do |k, v|
    attrs_list << { k => v }
  end
  res = _setup_reorganize_so_sort(attrs_list)
  res = _setup_reorganize_so_befaft(res)

  old = attrs_list.map { |attr| attr.keys[0] }
  new = res.map { |attr| attr.keys[0] }
  Lorj.debug(3, "unordered reorganized from '%s' to '%s'",
             old, new) unless old == new
  res
end
_setup_ros_add_attribute(step_order, stepo_index, attr_name) click to toggle source

Internal function to add an attribute to the step_order structure.

# File lib/core/core_setup_init.rb, line 490
def _setup_ros_add_attribute(step_order, stepo_index, attr_name)
  step_order[stepo_index] = [] if step_order[stepo_index].nil?
  step_order[stepo_index] << attr_name
end
_setup_ros_find_buildstep(build_steps, step_order_index, searched_step_name) click to toggle source

Internal Function searching in build_steps a step_name. If found, the index is kept.

If found, it compares the index with the current step_index It will be considered valid if the step index has a step_index in :orders or if the step_index - 1 is the found in the last known step.

If the step is not found, the index returned will be a new index to create in build_steps.

  • args:

    • build_steps : List of build_steps already identified.

    • step_order_index : current step order index to add an attribute to.

    • step_name : Step name to search.

  • return:

    • index : It returns a correct build_step to use.

    • nil : nil if there is no valid index to return.

# File lib/core/core_setup_init.rb, line 568
def _setup_ros_find_buildstep(build_steps, step_order_index,
                                searched_step_name)
  return 0 if step_order_index == 0

  step_found = nil
  last_step_order_found = nil

  build_steps.each_index do |i|
    step_found = i if build_steps[i][:name] == searched_step_name
    if build_steps[i][:order].include?(step_order_index - 1)
      last_step_order_found = i
    end
  end

  return build_steps.length if step_found.nil?

  if step_found
    if build_steps[step_found][:order].include?(step_order_index)
      return step_found
    end

    return step_found if step_found >= last_step_order_found
  end

  PrcLib.warning("Unable to set step '%s' at position %s. "\
                 "This step is already at position '%s'. "\
                 "Due to attribute dependencies, attribute '%' cannot be"\
                 ' asked at that step. Please correct the process'\
                 ' definition. ',
                 step_name, build_steps.index(e),
                 build_steps.length - 1, attr_name)
  nil
end
_setup_ros_get_step_name(attr_def) click to toggle source

Internal function to get the step name to use

# File lib/core/core_setup_init.rb, line 473
def _setup_ros_get_step_name(attr_def)
  return nil if attr_def[:ask_step].nil?

  step_name = attr_def[:ask_step]
  step_name = step_name.to_s if step_name.is_a?(Fixnum)
  step_name
end
_setup_ros_same_step_name(build_step, stepo_index, step_name, attr_name) click to toggle source

Internal function checking if the step is already assigned

# File lib/core/core_setup_init.rb, line 482
def _setup_ros_same_step_name(build_step, stepo_index, step_name, attr_name)
  return false unless step_name.nil? || build_step[:name] == step_name

  _setup_ros_add_attribute(build_step[:order], stepo_index, attr_name)
  true
end
_setup_ros_set_step(params) click to toggle source

Set the step data to the current order built.

If the step has already been set, a warning is printed.

  • returns:

    • +Return the

# File lib/core/core_setup_init.rb, line 504
def _setup_ros_set_step(params)
  build_steps = params[:build_steps]
  build_step = params[:build_step]
  step_index = params[:step_index]
  step_name = params[:step_name]
  attr_name = 'of latest step'
  attr_name = params[:attr_name] unless params[:attr_name].nil?

  setup_step = params[:setup_steps][step_name]
  if setup_step.nil?
    PrcLib.warning("Attribute '%s': Setup step '%s' is not defined.",
                   attr_name, step_name)
    return build_step
  end

  step_found = _setup_ros_find_buildstep(build_steps, step_index,
                                         step_name)

  return build_step if step_found.nil?

  if step_found == build_steps.length
    step = { :order => { step_index => [] } }
    Lorj.debug(3, "Building setup step position '%s'", step_found)
    build_steps << step
  end

  build_step = step_found
  step = build_steps[build_step]

  return build_step if step[:name] == step_name

  step[:name] = step_name

  step[:desc] = setup_step[:desc]
  step[:explanation] = setup_step[:explanation]
  step[:pre_step_handler] = setup_step[:pre_step_function]
  step[:post_step_handler] = setup_step[:post_step_function]

  Lorj.debug(3, "Requested by '%s' attribute, setup step position '%s'"\
                " is assigned to '%s'", attr_name,
             build_steps.length - 1, step_name)
  build_step
end
_setup_set_group_case1(attrs_done, attr_name, group, objs) click to toggle source

Case 1 - equivalent group?

# File lib/core/core_setup_init.rb, line 837
def _setup_set_group_case1(attrs_done, attr_name, group, objs)
  attrs_done.each do |k, v|
    next unless v.rh_get(:group, :objs) == objs ||
                (v.rh_get(:group, :objs).length == 0 && v[:obj] == objs[0])

    group[:level] = v.rh_get(:group, :level)
    Lorj.debug(5, "attr setup '%s': Equivalent: '%s' group level set to %s",
               attr_name, k, group[:level])
    return false
  end
  true
end
_setup_set_group_case2(dependencies, attrs_done, attr_name, group, objs) click to toggle source

case 2 - existing group found as subgroup?

# File lib/core/core_setup_init.rb, line 851
def _setup_set_group_case2(dependencies, attrs_done, attr_name, group, objs)
  attr_subgroups = []
  level = nil
  attrs_done.each do |k, v|
    group_to_check = v.rh_get(:group, :objs)
    next if objs - [v[:obj]] == objs && objs - group_to_check == objs

    attr_subgroups << k
    if level.nil?
      level = v.rh_get(:group, :level)
    else
      level = [v.rh_get(:group, :level), level].max
    end
  end

  if level
    group[:level] = level
    Lorj.debug(5, "attr setup '%s': group level set to %s",
               attr_name, group[:level])

    attr_subgroups.each do |v|
      group = dependencies.rh_get(:attributes, v, :group)
      group[:level] += -1
      Lorj.debug(5, "attr setup '%s': attribute subgroup '%s' level"\
                    ' decreased: group level set to %s',
                 attr_name, v, group[:level])
    end
    return false
  end
  true
end
_setup_set_group_case34(attrs_done, attr_name, group, objs) click to toggle source

case 3 - Is a subgroup of existing group?

# File lib/core/core_setup_init.rb, line 884
def _setup_set_group_case34(attrs_done, attr_name, group, objs)
  group[:level] = -1 # default is case 4 - new group!

  attrs_done.each_value do |v|
    group_to_check = v.rh_get(:group, :objs)
    next if group_to_check - objs == group_to_check

    group[:level] = [group[:level], v.rh_get(:group, :level) - 1].min
  end
  Lorj.debug(5, "attr setup '%s': group level set to '%s'",
             attr_name, group[:level])
end
_setup_set_group_level(dependencies, attrs_done, attr_name, group, objs) click to toggle source

Function parsing the attrs_done to found equivalent group or subgroup.

    1. search for equivalent group

    copy the equivalent group level to the group tested. return if updated

    1. search for any subgroup already treated.

    The group will get the highest level each subgroup (part of the new group) will be decreased. return if updated

    1. loop in groups if the tested group is a subgroup of an existing group

    The group tested will get the lowest group level - 1 return if updated

    1. the group level is set with -1

# File lib/core/core_setup_init.rb, line 828
def _setup_set_group_level(dependencies, attrs_done, attr_name, group, objs)
  return unless _setup_set_group_case1(attrs_done, attr_name, group, objs)
  return unless _setup_set_group_case2(dependencies, attrs_done,
                                       attr_name, group, objs)

  _setup_set_group_case34(attrs_done, attr_name, group, objs)
end
_setup_step_definition() click to toggle source
# File lib/core/core_setup_init.rb, line 77
def _setup_step_definition
  setup_steps = {}
  steps = Lorj.data.setup_data(:steps)
  return setup_steps if steps.nil?

  steps.each do |name, value|
    setup_steps[name] = value
  end

  ask_steps = Lorj.data.setup_data(:ask_step)
  return setup_steps if ask_steps.nil?

  ask_steps.each do |value|
    name = value[:name]
    name = ask_steps.index(value).to_s if name.nil?
    if setup_steps.key?(name)
      setup_steps[name].rh_merge(value)
      next
    end
    setup_steps[name] = value
  end
  setup_steps
end
_sid_show_debug(level, str, attrs, objects) click to toggle source

Internal setup function to display debug info related to _setup_identify_deps

# File lib/core/core_setup_init.rb, line 278
def _sid_show_debug(level, str, attrs, objects)
  data = []
  data << format("'%s' attributes", attrs.join(', ')) if attrs.length > 0

  data << format("'%s' objects", objects.join(', ')) if objects.length > 0

  Lorj.debug(level, str, data.join(' and ')) if data.length > 0
end
account_data_import(data, name = nil) click to toggle source

Function to import an account data in Lorj::Account.

The 'account' layer is not cleaned before. If you need to clean it up, do:

config.ac_new(account_name, controller_name)

or if the Hash data contains :name and :provider

config.ac_erase

To save it in a file, you will need to call

config.ac_save(filename)

If you pass 'name' and 'controller', ac_update will be used to update the account data If the imported data contains name and controller data, by default, it will call ac_update.

The location used comes from PrcLib.data_path Passwords will be encrypted by the internal .key file stored in PrcLib.pdata_path

The imported Hash will follow the process data model. But it won't verify if some data are missed for any object action (create/delete/…)

  • Args :

    • data : Account data to import.

    • name : Optional. Name of the account.

  • Raises : No exceptions

# File lib/core/core_import_export.rb, line 100
def account_data_import(data, name = nil)
  _update_account_meta(data, name)

  entr = _get_encrypt_key

  data.each do |s, sh|
    sh.each do |k, v|
      key = "#{s}##{k}"
      data_def = Lorj.data.auto_section_data(key)
      if data_def && data_def[:encrypted].is_a?(TrueClass)
        v = Lorj::SSLCrypt.encrypt_value(v, entr)
      end
      config.set(key, v, :name => 'account')
    end
  end
end
account_export(map = nil, with_name = true, account_only = true, processes_options = {}) click to toggle source

Function to export a Lorj Account in an encrypted Hash.

The encrypted Hash will be encrypted by a new key returned. The content of the hash will built thanks to a Hash mapping or the list of data list in the config 'account' layer.

  • Args :

    • map : Hash map of fields to extract. if map is nil, the export function will loop in the list of keys in the 'account' layer. if map is provided, following data are expected:

      • <key> : Data key to extract from config.

        • :keys: Array. SubHash tree of keys to create. If :keys is missing, the Data key will define the SubHash tree to use.

          Ex:

          map = {
            # like :keys => [credentials, auth_uri]
            'credentials#auth_uri' => {},
            # extract from maestro but export under :server
            'maestro#image_name' => {:keys => [:server, image_name]}
            }
          
    • with_name : True to extract :name and :provider as well. True by default.

    • account_only : True data extracted must come exclusively from the config 'account' layer.

    • processes_options : Hash. Export options for processes

      • :exclude: Array. name of process to exclude.

  • returns :

    • key: String. Key used to encrypt.

    • env_hash: String. Base64 encrypted Hash.

    OR

    • nil if issues.

# File lib/core/core_import_export.rb, line 150
def account_export(map = nil, with_name = true, account_only = true,
                   processes_options = {})
  map = _account_map if map.nil?

  map.merge!('account#name' => {}, 'account#provider' => {}) if with_name

  entr = _get_encrypt_key
  rhash = {}
  map.each do |k, v|
    data_def = Lorj.data.auto_section_data(k)

    if account_only
      data = config.get(k, nil, :name => 'account')
    else
      data = config[k]
    end

    rhash_kpath = _export_keys_as_keypath(k, v)
    if !data_def.nil? && data_def[:encrypted].is_a?(TrueClass)
      data = Lorj::SSLCrypt.get_encrypted_value(data, entr, data_def[:desc])
    end
    rhash.rh_set(data, *(rhash_kpath.tree))
  end

  entr = Lorj::SSLCrypt.new_encrypt_key
  export_data = { :enc_data => Lorj::SSLCrypt.encrypt_value(rhash.to_yaml,
                                                            entr) }
  export_data[:processes] = _export_processes(processes_options)
  [entr, export_data.to_yaml]
end
cache_objects_keys() click to toggle source

Function to get Lorj core data cache keys.

Args

Return

  • List of objects in cache.

# File lib/core/lorj_basedefinition.rb, line 185
def cache_objects_keys
  @object_data[].keys
end
config() click to toggle source

Reference to the config object.

See Lorj::Config or Lorj::Account for details

# File lib/core/lorj_basedefinition.rb, line 71
def config
  PrcLib.runtime_fail 'No config object loaded.' unless @config
  @config
end
controller_connect(sObjectType, params = nil) click to toggle source

controller_connect call lorj framework to execute a controller connection task

parameters:

  • object_type: Lorj object type to use for the connection.

  • params : Parameters to use for connection.

# File lib/core/core_controller.rb, line 30
def controller_connect(sObjectType, params = nil)
  _add_instant_config(params)

  controller_params = _get_controller_params(sObjectType,
                                             :create_e, :connect)
  controller_obj = @controller.connect(sObjectType, controller_params)
  data_obj = Lorj::Data.new
  data_obj.base = self
  data_obj.set(controller_obj, sObjectType) do |sObjType, oObject|
    begin
      _return_map(sObjType, oObject)
   rescue => e
     PrcLib.runtime_fail 'connect %s.%s : %s',
                         @process.class, sObjectType, e.message
    end
  end
  @object_data.add data_obj
  data_obj
end
controller_create(sObjectType, params = nil) click to toggle source

controller_create call lorj framework to execute a controller creation task

parameters:

  • object_type: Lorj object type to use for the creation.

  • params : Parameters to use for creation.

# File lib/core/core_controller.rb, line 55
def controller_create(sObjectType, params = nil)
  _add_instant_config(params)

  # The process ask the controller to create the object.
  # controller_params have to be fully readable by the controller.
  controller_params = _get_controller_params(sObjectType,
                                             :create_e, :create)
  controller_obj = @controller.create(sObjectType, controller_params)
  data_obj = Lorj::Data.new
  data_obj.base = self
  data_obj.set(controller_obj, sObjectType) do |sObjType, oObject|
    begin
      _return_map(sObjType, oObject)
   rescue => e
     PrcLib.runtime_fail 'create %s.%s : %s',
                         @process.class, sObjectType, e.message
    end
  end
  @object_data.add data_obj

  _remove_instant_config(params)

  data_obj
end
controller_delete(sObjectType, params = nil) click to toggle source

controller_delete call lorj framework to execute a controller deletion task

parameters:

  • object_type: Lorj object type to use for the deletion.

  • params : Parameters to use for deletion.

returns:

  • The controller must return true to inform about the real deletion

# File lib/core/core_controller.rb, line 89
def controller_delete(sObjectType, params = nil)
  _add_instant_config(params)

  controller_params = _get_controller_params(sObjectType,
                                             :delete_e, :delete)
  PrcLib.runtime_fail "delete Controller - %s: Object '%s' is not loaded.",
                      @controller.class,
                      key unless controller_params.exist?(sObjectType)
  state = @controller.delete(sObjectType, controller_params)
  @object_data.delete(sObjectType) if state

  _remove_instant_config(params)

  state
end
controller_get(sObjectType, sUniqId, params = nil) click to toggle source

controller_get call lorj framework to execute a controller get task

parameters:

  • object_type: Lorj object type to use for the get.

  • params : Parameters to use for get.

returns:

  • Return a Lorj::Data representing the data retrieved by the controller.

# File lib/core/core_controller.rb, line 113
def controller_get(sObjectType, sUniqId, params = nil)
  _add_instant_config(params)

  controller_params = _get_controller_params(sObjectType,
                                             :get_e, :get)

  controller_obj = @controller.get(sObjectType, sUniqId, controller_params)
  data_obj = Lorj::Data.new
  data_obj.base = self
  data_obj.set(controller_obj, sObjectType) do |sObjType, oObject|
    begin
      _return_map(sObjType, oObject)
   rescue => e
     PrcLib.runtime_fail 'get %s.%s : %s',
                         @process.class, sObjectType, e.message
    end
  end
  @object_data.add data_obj

  _remove_instant_config(params)

  data_obj
end
controller_query(sObjectType, hQuery, params = nil) click to toggle source

controller_query call lorj framework to execute a controller query task

parameters:

  • object_type: Lorj object type to use for the query.

  • params : Parameters to use for query.

returns:

# File lib/core/core_controller.rb, line 145
def controller_query(sObjectType, hQuery, params = nil)
  _add_instant_config(params)

  # Check if we can re-use a previous query
  list = @object_data[:query, sObjectType]
  unless list.nil?
    if list[:query] == hQuery
      Lorj.debug(3, "Using Object '%s' query cache : %s",
                 sObjectType, hQuery)
      return list
    end
  end

  controller_params = _get_controller_params(sObjectType,
                                             :query_e, :query)
  controller_query = _query_map(sObjectType, hQuery)

  controller_obj = @controller.query(sObjectType, controller_query,
                                     controller_params)

  data_obj = Lorj::Data.new :list
  data_obj.base = self
  data_obj.set(controller_obj,
               sObjectType, hQuery) do |sObjType, key|
    begin
      _return_map(sObjType, key)
   rescue => e
     PrcLib.runtime_fail 'query %s.%s : %s',
                         @process.class, sObjectType, e.message
    end
  end

  Lorj.debug(2, 'Object %s - queried. Found %s object(s).',
             sObjectType, data_obj.length)

  @object_data.add data_obj

  _remove_instant_config(params)

  data_obj
end
controller_refresh(sObjectType, data_obj) click to toggle source

controller_refresh call lorj framework to execute a controller refresh task

The controller must respect the following rule:

  • If the refresh was unsuccessful, due to errors, the original object should be kept intact.

  • A boolean should be return to inform that therefresh was executed successfully or not.

  • parameters:

    • object_type: Lorj object type to use for the refresh.

    • object : object to refresh.

  • returns:

    • boolean: true if refresh was executed successfully. false otherwise.

# File lib/core/core_controller.rb, line 265
def controller_refresh(sObjectType, data_obj)
  return false unless data_obj.is_a?(Lorj::Data) && !data_obj.empty?

  controller_obj = data_obj[:object]

  is_refreshed = @controller.refresh(sObjectType, controller_obj)

  PrcLib.runtime_fail "Controller function 'refresh' must return true or "\
                      "false. Class returned: '%s'",
                      is_refreshed.class unless is_refreshed.boolean?

  Lorj.debug(1, '%s.%s - refreshed.',
             @process.class, sObjectType) if is_refreshed

  data_obj.set(controller_obj, sObjectType) do |sObjType, an_object|
    begin
      _return_map(sObjType, an_object)
   rescue => e
     PrcLib.runtime_fail 'update %s.%s : %s',
                         @process.class, sObjectType, e.message
    end
  end

  is_refreshed
end
controller_update(sObjectType, params = nil) click to toggle source

controller_update call lorj framework to execute a controller update task

parameters:

  • object_type: Lorj object type to use for the update.

  • params : Parameters to use for update.

returns:

  • The controller must return true to inform about the real deletion

# File lib/core/core_controller.rb, line 195
def controller_update(sObjectType, params = nil)
  _add_instant_config(params)

  # Need to detect data updated and update the Controler object with the
  # controler

  controller_params = _get_controller_params(sObjectType,
                                             :update_e, :update)

  data_obj = @object_data[sObjectType, :ObjectData]
  controller_obj = data_obj[:object]

  is_updated = false
  attributes = data_obj[:attrs]
  attributes.each do |key, value|
    attribute_obj = KeyPath.new(key)

    attribute_map = PrcLib.model.meta_obj.rh_get(sObjectType, :returns,
                                                 attribute_obj.fpath)
    attr_map_obj = KeyPath.new(attribute_map)
    old_value = @controller.get_attr(controller_obj, attr_map_obj.tree)

    next if value == old_value

    is_updated = true
    @controller.set_attr(controller_obj, attr_map_obj.tree, value)
    Lorj.debug(2, '%s.%s - Updating: %s = %s (old : %s)',
               @process.class, sObjectType, key, value, old_value)
  end

  is_done = @controller.update(sObjectType, data_obj,
                               controller_params) if is_updated

  PrcLib.runtime_fail "Controller function 'update' must return True or "\
                      "False. Class returned: '%s'",
                      is_done.class unless is_done.boolean?

  Lorj.debug(1, '%s.%s - updated.',
             @process.class, sObjectType) if is_done
  data_obj.set(controller_obj, sObjectType) do |sObjType, an_object|
    begin
      _return_map(sObjType, an_object)
   rescue => e
     PrcLib.runtime_fail 'update %s.%s : %s',
                         @process.class, sObjectType, e.message
    end
  end

  _remove_instant_config(params)

  is_done
end
data_objects(sObjectType, *key) click to toggle source

Function to get attributes of objects stored in the Lorj core data cache.

Args

  • object_type : Object type to get

  • *key : tree of keys to get values.

    The syntax is defined by Lorj::Data[]
    

Return

# File lib/core/lorj_basedefinition.rb, line 174
def data_objects(sObjectType, *key)
  @object_data[sObjectType, *key]
end
erb(str) click to toggle source

function to interpret a template data, and use ERBConfig as data context. ERBConfig contains config object only.

# File lib/core/definition.rb, line 342
def erb(str)
  ERB.new(str).result(@erb_config.get_binding)
end
format_object(object_type, oMiscObject) click to toggle source
# File lib/core/lorj_basedefinition.rb, line 86
def format_object(object_type, oMiscObject)
  return nil unless [String, Symbol].include?(object_type.class)

  object_type = object_type.to_sym if object_type.class == String

  { :object_type => object_type,
    :attrs => {},
    :object => oMiscObject
  }
end
format_query(sObjectType, oControlerObject, hQuery) click to toggle source
# File lib/core/lorj_basedefinition.rb, line 76
def format_query(sObjectType, oControlerObject, hQuery)
  {
    :object => oControlerObject,
    :object_type => :object_list,
    :list_type => sObjectType,
    :list => [],
    :query => hQuery
  }
end
get_data(oObj, *key) click to toggle source

get an attribute/object/… from an object.

# File lib/core/lorj_basedefinition.rb, line 190
def get_data(oObj, *key)
  if oObj.is_a?(Hash) && oObj.key?(:object_type)
    object_data = ObjectData.new
    object_data << oObj
  else
    object_data = @object_data
  end
  object_data[oObj, *key]
end
get_data_metadata(sKey) click to toggle source
# File lib/core/lorj_basedefinition.rb, line 97
def get_data_metadata(sKey)
  _get_meta_data(sKey)
end
object_cleanup(object_type) click to toggle source

Function to clean the cache for a specific meta lorj object.

  • Args :

    • ObjectType : Meta object type to cleanup.

  • Returns : no data

  • Raises :

# File lib/core/core_process.rb, line 181
def object_cleanup(object_type)
  object = @object_data[object_type, :ObjectData]

  @object_data.delete(object) unless object.nil?
end
process_create(object_type, hConfig = nil) click to toggle source

Call meta lorj object creation process. The creation process can implement any logic like:

  • create an object in the DB.

  • check object existence in the DB. If not exists, create it.

  • Args :

    • ObjectType : Meta object type to create.

    • Config : Optional. Hash containing list of data to use for

creation.

  • Returns :

  • Object : Lorj::Data object of type ObjectType created.

OR

  • Lorj::Data empty.

  • Raises :

    • Warning if the create_e process handler did not return any data. (nil)

    • Warning if the Config data passed are not required by the meta object (or dependencies) at creation time.

    • Error if ObjectType has never been declared.

    • Error if the dependencies create_e process handler did not return any data. (nil) - Loop detection.

    • Error if the create_e process handler raise an error.

# File lib/core/core_process.rb, line 46
def process_create(object_type, hConfig = nil)
  return nil unless object_type.is_a?(Symbol)

  _add_instant_config(hConfig)

  unless PrcLib.model.meta_obj.rh_exist?(object_type)
    PrcLib.runtime_fail "%s.%s: '%s' is not a known object type.",
                        self.class, __callee__, object_type
  end
  proc = PrcLib.model.meta_obj.rh_get(object_type, :lambdas, :create_e)

  # Check required parameters
  _process_load_dependencies(object_type, proc, :create_e, __callee__)

  # Context: Default object used
  @runtime_context[:oCurrentObj] = object_type

  if proc.nil?
    # This object is a meta object, without any data.
    # Used to build other kind of objects.
    object = Lorj::Data.new
    object.base = self
    object.set({}, object_type) {}
  else
    # build Function params to pass to the event handler.
    params = _get_process_params(object_type, :create_e, proc)
    Lorj.debug(2, "Create Object '%s' - Running '%s'", object_type, proc)

    # Call the process function.
    # At some point, the process will call the controller, via the framework
    # This controller call via the framework has the role to
    # create an ObjectData well formatted, with _return_map function
    # See Definition.connect/create/update/query/get functions (lowercase)
    object = @process.method(proc).call(object_type, params)
    # return usually is the main object that the process called should
    # provide.
    # Save Object if the object has been created by the process, without
    # controller
  end

  _remove_instant_config(hConfig)

  if object.nil?
    PrcLib.warning("'%s' has returned no data for object Lorj::Data '%s'!",
                   proc, object_type)
    Lorj::Data.new
  else
    query_cleanup(object_type)
    @object_data.add(object)
  end
end
process_delete(object_type, hConfig = nil) click to toggle source

Call meta lorj object deletion process There is no implementation of cascade deletion. It is up to the process to do it or not.

  • Args :

    • ObjectType : Meta object type to create.

    • Config : Optional. Hash containing list of data to use for

creation.

  • Returns :

    • Deleted : true if deleted or false otherwise.

  • Raises :

    • Warning if the create_e process handler did not return any data. (nil)

    • Warning if the Config data passed are not required by the meta object (or dependencies) at creation time.

    • Error if ObjectType has never been declared.

    • Error if the dependencies query_e process handler did not return any data. (nil) - Loop detection.

    • Error if the query_e process handler raise an error.

# File lib/core/core_process.rb, line 119
def process_delete(object_type, hConfig = nil)
  return nil unless object_type.is_a?(Symbol)

  _add_instant_config(hConfig)

  unless PrcLib.model.meta_obj.rh_exist?(object_type)
    PrcLib.runtime_fail "%s.%s: '%s' is not a known object type.",
                        self.class, __callee__, object_type
  end

  proc = PrcLib.model.meta_obj.rh_get(object_type, :lambdas, :delete_e)

  if proc.nil?
    _remove_instant_config(hConfig)
    return nil
  end

  # Check required parameters
  _process_load_dependencies(object_type, proc, :delete_e, __callee__)

  # Context: Default object used.
  @runtime_context[:oCurrentObj] = object_type

  # build Function params to pass to the event handler.
  params = _get_process_params(object_type, :delete_e, proc)

  state = @process.method(proc).call(object_type, params)
  # return usually is the main object that the process called should provide

  _remove_instant_config(hConfig)

  @object_data.delete(object_type) if state
end
process_get(object_type, sUniqId, hConfig = nil) click to toggle source

Function to execute a get process. This function returns a Lorj::Data of type :object.

  • Args :

    • ObjectType : Meta object type to query.

    • UniqId : Uniq ID.

    • Config : Optional. Hash containing list of data to use for

      getting.
  • Returns :

  • Lorj::Data of type :object

OR

  • Lorj::Data empty.

  • Raises :

    • Warning if the Config data passed are not required by the meta object (or dependencies) at creation time.

    • Error if ObjectType has never been declared.

    • Error if the dependencies get_e process handler did not return any data. (nil) - Loop detection.

    • Error if the get_e process handler raise an error.

# File lib/core/core_process.rb, line 294
def process_get(object_type, sUniqId, hConfig = nil)
  return nil unless object_type.is_a?(Symbol)

  _add_instant_config(hConfig)

  unless PrcLib.model.meta_obj.rh_exist?(object_type)
    PrcLib.runtime_fail "$s.: '%s' is not a known object type.",
                        self.class, __callee__, object_type
  end

  proc = PrcLib.model.meta_obj.rh_get(object_type, :lambdas, :get_e)

  if proc.nil?
    _remove_instant_config(hConfig)
    return nil
  end

  # Check required parameters
  _process_load_dependencies(object_type, proc, :get_e, __callee__)

  # Context: Default object used
  @runtime_context[:oCurrentObj] = object_type

  # build Function params to pass to the Process Event handler.
  params = _get_process_params(object_type, :get_e, proc)

  # Call the process function.
  # At some point, the process will call the controller, via the framework.
  # This controller call via the framework has the role to
  # create an ObjectData well formatted, with _return_map function
  # See Definition.connect/create/update/query/get functions (lowercase)
  object = @process.method(proc).call(object_type, sUniqId, params)
  # return usually is the main object that the process called should provide

  _remove_instant_config(hConfig)

  if object.nil?
    PrcLib.warning("'%s' has returned no data for object Lorj::Data '%s'!",
                   proc, object_type)
    Lorj::Data.new
  else
    @object_data.add(object)
  end
end
process_query(object_type, hQuery, hConfig = nil) click to toggle source

Function to execute a query process. This function returns a Lorj::Data of type :list.

  • Args :

    • ObjectType : Meta object type to query.

    • Query : Hash. Represent the query to execute.

    • Config : Optional. Hash containing list of data to use for query

  • Returns : Lorj::Data of type :list

OR

# File lib/core/core_process.rb, line 203
def process_query(object_type, hQuery, hConfig = nil)
  return nil unless object_type.is_a?(Symbol)

  _add_instant_config(hConfig)

  unless PrcLib.model.meta_obj.rh_exist?(object_type)
    PrcLib.runtime_fail "%s.%s: '%s' is not a known object type.",
                        self.class, __callee__, object_type
  end

  # Check if we can re-use a previous query
  list = query_cache(object_type, hQuery)
  unless list.nil?
    _remove_instant_config(hConfig)
    return list
  end

  proc = PrcLib.model.meta_obj.rh_get(object_type, :lambdas, :query_e)

  if proc.nil?
    _remove_instant_config(hConfig)
    return nil
  end

  # Check required parameters
  _process_load_dependencies(object_type, proc, :query_e, __callee__)

  # Context: Default object used.
  @runtime_context[:oCurrentObj] = object_type

  # build Function params to pass to the Process Event handler.
  params = _get_process_params(object_type, :query_e, proc)

  # Call the process function.
  # At some point, the process will call the controller, via the framework.
  # This controller call via the framework has the role to
  # create an ObjectData well formatted, with _return_map function
  # See Definition.connect/create/update/query/get functions (lowercase)
  object = @process.method(proc).call(object_type, hQuery, params)

  _remove_instant_config(hConfig)

  # return usually is the main object that the process called should provide
  if object.nil?
    PrcLib.warning("'%s' returned no collection of objects Lorj::Data "\
                   "for '%s'", proc, object_type)
    Lorj::Data.new
  else
    # Save Object if the object has been created by the process, without
    # controller
    @object_data.add(object)
  end
end
process_refresh(object) click to toggle source

Function to execute an object update. This function returns a Lorj::Data of type :object, refreshed.

It uses the event 'refresh_e'. If not defined, the refresh is simply not executed. No warning exposed, but a debug info is thrown.

refresh_e is defined and called as follow:

BaseDefinition class derived function. This Process function should do any task required to execute a refresh of the object passed. The controller object data should be extracted by the controller_refresh call to refresh :attrs. See controller_refresh. It should return true or false if the object refresh was done successfully or not

It is possible to call directly the controller_refresh as the process event

  • args:

    • object_type: The object_type to refresh

    • object : The Lorj::Data object to refresh

  • returns:

    • boolean : true if refresh was executed successfully. false otherwise.

From the object itself, you can call object.refresh. This will call this function.

The controller event usually called is controller_refresh.

  • Args :

    • object_type : Meta object type to query.

    • config : Optional. Hash containing list of data to use for

updating.

  • Returns :

    • boolean : true if the refresh was executed successfully. false otherwise.

  • Raises :

    • Warning if the Config data passed are not required by the meta object (or dependencies) at creation time.

    • Error if ObjectType has never been declared.

    • Error if the dependencies get_e process handler did not return any data. (nil) - Loop detection.

    • Error if the get_e process handler raise an error.

# File lib/core/core_process.rb, line 447
def process_refresh(object)
  return nil unless object.is_a?(Lorj::Data) && object.type == :object &&
                    !object.empty?

  object_type = object.object_type?

  unless PrcLib.model.meta_obj.rh_exist?(object_type)
    PrcLib.runtime_fail "$s.%s: '%s' is not a known object type.",
                        self.class, __callee__, object_type
  end

  proc = PrcLib.model.meta_obj.rh_get(object_type, :lambdas, :refresh_e)

  if proc.nil?
    Lorj.debug(1, "No 'refresh_e' event found for object type '%s'",
               object_type)
    return false
  end

  ret = @process.method(proc).call(object_type, object)

  unless ret.boolean?
    Lorj.debug(1, "'%s' has not returned a boolean. Consider return false.",
               object_type)
    ret = false
  end
  ret
end
process_setup(sObjectType) click to toggle source

Setup process. The setup process is used to ask the end user to provide some data. You can call it before you run an action, or during a configution setting of your application.

setup will be exposed to the end user per several steps, and config data to ask in a specific order, with optionnally some explanations, possible values (hard coded list of values or queried from the model) and default value.

Ex: Step 1 description : *Provider configuration*: explanation : You are going to setup your account information

ask a config data: Enter my account name:  |myuser|
ask others data  : Enter ...

Step 2 description : *Another configuration to setup*:

ask several data : Enter ...

etc…

Steps are predefined in the application defaults.yaml from /:setup/:ask_step Commonly, each step can define the following options:

  • :desc: Required. Define the step description.

    ERB template enable. To get config data,
    type <%= config[...] %>
  • :explanation: |- Optional. Define a multiline explanation. This is

    printed out in brown color.
    ERB template enable. To get config data, type
    <%= config[...] %>

For details or more options, see core_model.rb

config data are initially identified by the Object model dependency. (See obj_needs model declaration.)

The 'object_type' passed as parameter is the top level object in object dependency. each config data are sorted by object dependencies and additionnal options defined in the application defaults.yaml at: /:section/<section name>/<data>/ See lib/core/code_model.rb

setup will ask only data which are configured with :account => true /:section/<section name>/<data>/:account => true

Additional config data can added to the list thanks to: /:setup/:ask_step/:add/

Commonly, each data can define the following options:

  • :account: Optional. default: False

    => setup will ask the data only if :account is true
  • :desc: Required if :account is true. String. default: nil

    => Description
  • :explanation: |- Print a multiline explanation before asking the data

    ERB template enable. To get config data,
    type <%= config[...] %>
  • :ask_sort: Number sort position.

  • :after: Name of the previous <Data> to ask before the

    current one.
  • :depends_on: Additional data dependency.

  • :default_value: Default value at setup time.

  • :validate: Regular expression to validate end user input

    during setup.
  • :list_values: Additional options to get a list of possible values.

  • :post_step_function Function to call after data asked to the user. This function must return a boolean:

    • true : The data is accepted and setup will go further.

    • false: The data is NOT accepted and setup will ask the data again. setup will loop until the function is happy with (return true)

  • :pre_step_function Function to call before data is asked to the user. This function must return a boolean:

    • true : setup will ask the data.

    • false: setup will skip asking the data.

For details or more options, see core_model.rb

Setup is based on a config object which requires to have at least following functions:

  • value = get(key, default)

  • set(key, value)

You can create you own config class, derived from Lorj::Config.

When setup has done to ask data to the user, the config object is updated. It is up to you and your application to decide what you want to do with those data. Usually, if your application uses setup to setup an account settings Lorj::Account or some local application defaults Lorj::Config, you may want to save them to a configuration file. If you are using Lorj::Account, use function ac_save If you are using Lorj::Config, use function config_save

  • Args :

    • ObjectType : Top object type to ask.

  • Returns :

    • nothing.

  • Raises :

# File lib/core/core_process_setup.rb, line 127
def process_setup(sObjectType)
  unless PrcLib.model.meta_obj.rh_exist?(sObjectType)
    PrcLib.runtime_fail "Setup: '%s' not a valid object type."
  end

  Lorj.debug(2, "Setup is identifying account data to ask for '%s'",
             sObjectType)
  # Loop in dependencies to get list of data object to setup
  setup_steps = _setup_identify(sObjectType, _setup_load)

  Lorj.debug(2, 'Setup check if needs to add unrelated data in the process')
  _setup_check_additional(setup_steps)

  Lorj.debug(2, "Setup will ask for :\n %s", setup_steps.to_yaml)

  _setup_ask(setup_steps)

  PrcLib.info("Configuring account : '#{config[:name]}',"\
              " provider '#{config[:provider]}'")
end
process_update(object_type, hConfig = nil) click to toggle source

Function to execute a update process. This function returns a Lorj::Data of type :object.

  • Args :

    • object_type : Meta object type to query.

    • config : Optional. Hash containing list of data to use for

updating.

  • Returns :

    OR

  • Raises :

    • Warning if the Config data passed are not required by the meta object (or dependencies) at creation time.

    • Error if ObjectType has never been declared.

    • Error if the dependencies get_e process handler did not return any data. (nil) - Loop detection.

    • Error if the get_e process handler raise an error.

# File lib/core/core_process.rb, line 360
def process_update(object_type, hConfig = nil)
  return nil unless object_type.is_a?(Symbol)

  _add_instant_config(hConfig)

  unless PrcLib.model.meta_obj.rh_exist?(object_type)
    PrcLib.runtime_fail "$s.%s: '%s' is not a known object type.",
                        self.class, __callee__, object_type
  end

  proc = PrcLib.model.meta_obj.rh_get(object_type, :lambdas, :update_e)

  if proc.nil?
    _remove_instant_config(hConfig)
    return nil
  end

  _process_load_dependencies(object_type, proc, :update_e, __callee__)

  # Context: Default object used.
  @runtime_context[:oCurrentObj] = object_type

  # build Function params to pass to the event handler.
  params = _get_process_params(object_type, :update_e, proc)

  object = @process.method(proc).call(object_type, params)
  # return usually is the main object that the process called should provide

  _remove_instant_config(hConfig)

  if object.nil?
    PrcLib.warning("'%s' has returned no data for object Lorj::Data '%s'!",
                   proc, object_type)
    Lorj::Data.new
  else
    @object_data.add(object)
  end
end
query_cache(object_type, hQuery) click to toggle source
# File lib/core/core_process.rb, line 257
def query_cache(object_type, hQuery)
  # Check if we can re-use a previous query
  list = @object_data[:query, object_type]

  return if list.nil?

  if list[:query] == hQuery
    Lorj.debug(3, "Using Object '%s' query cache : %s",
               object_type, hQuery)
    return list
  end

  nil
end
query_cleanup(object_type) click to toggle source

Function to clean the cache for a specific meta lorj object queried.

  • Args :

    • ObjectType : Meta object type to cleanup.

  • Returns : no data

  • Raises :

# File lib/core/core_process.rb, line 163
def query_cleanup(object_type)
  list = @object_data[:query, object_type]
  return if list.nil?

  @object_data.delete(list)
  Lorj.debug(2, "Query cache for object '%s' cleaned.", object_type)
end
register(oObject, sObjectType = nil, sDataType = :object) click to toggle source

Register the object to the internal @object_data instance

# File lib/core/lorj_basedefinition.rb, line 148
def register(oObject, sObjectType = nil, sDataType = :object)
  if oObject.is_a?(Lorj::Data)
    data_objects = oObject
  else
    PrcLib.runtime_fail "Unable to register an object '%s' "\
                         'as Lorj::Data object if ObjectType is not given.',
                        oObject.class unless sObjectType
    data_objects = Lorj::Data.new(sDataType)
    data_objects.base = self
    data_objects.set(oObject, sObjectType) do |sObjType, oControlerObject|
      _return_map(sObjType, oControlerObject)
    end
  end
  @object_data.add data_objects
end

Private Instance Methods

_account_map() click to toggle source
# File lib/core/core_import_export.rb, line 230
def _account_map
  map = {}

  config.each(:name => 'account') do |s, v|
    next unless v.is_a?(Hash)
    v.keys.each do |k|
      unless s == :account && [:name, :provider].include?(k)
        map["#{s}##{k}"] = {}
      end
    end
  end
  map
end
_add_instant_config(hConfig) click to toggle source
# File lib/core/core_process.rb, line 481
def _add_instant_config(hConfig)
  return unless hConfig.is_a?(Hash)

  config = PRC::BaseConfig.new hConfig
  options = { :name => hConfig.object_id.to_s, :config => config,
              :set => false }

  @config.layer_add PRC::CoreConfig.define_layer(options)
end
_ask_encrypted(sDesc, default) click to toggle source

internal runtime function for process call Ask encrypted function executed by _ask

parameters:

- +sDesc+       : data description
- +default+     : encrypted default value

return:

  • value : encrypted value in Base64.

raise:

# File lib/core/core_setup_encrypt.rb, line 177
def _ask_encrypted(sDesc, default)
  entr = _get_encrypt_key

  enc_value = default unless default == ''

  value_hidden = _get_encrypted_value_hidden(sDesc, default, entr)

  value_free = ''
  while value_free == ''
    # ask for encrypted data.
    value_free = ask(format('Enter %s: |%s|', sDesc, value_hidden)) do |q|
      q.echo = '*'
    end
    if value_free == '' && enc_value
      value_free = Encryptor.decrypt(
        :value => Base64.strict_decode64(enc_value),
        :key => entr[:key],
        :iv => Base64.strict_decode64(entr[:iv]),
        :salt => entr[:salt]
      )
    else
      PrcLib.message('%s cannot be empty.', sDesc) if value_free == ''
    end
  end
  Lorj::SSLCrypt.encrypt_value(value_free, entr)
end
_build_data(new_params, param_obj, param_options) click to toggle source

internal runtime function for process call Build a process/controller parameter object (ObjectData)

parameters:

- +new_params+        : Parameters ObjectData
- +param_object+      : parameter object
- +param_options+     : parameter options

return:

  • value : return the parameter value added.

    The value comes :
    • from an existing param value if the param_options defines :extract_from

    • from config layers if exist

    • from param_option if set

OR

  • nil : if not found

raise:

# File lib/core/core_object_params.rb, line 63
def _build_data(new_params, param_obj, param_options)
  param_name = param_obj.key

  unless param_options[:extract_from].nil?
    value = new_params[param_options[:extract_from]]
    new_params[param_obj.tree] = value
    return value
  end

  return nil unless param_options.key?(:default_value) ||
                    @config.exist?(param_name)

  default = param_options.rh_get(:default_value)
  value = @config.get(param_name, default)
  new_params[param_obj.tree] = value

  value
end
_build_hdata(object_type, new_params, param_obj, param_options, value) click to toggle source

internal runtime function for process call Build a process/controller parameter object (ObjectData)

parameters:

- +object_type+   : object type needing this parameter.
- +new_params+    : Parameters ObjectData
- +param_obj+     : parameter object
- +param_options+ : parameter options
  - :type   : hdata requires parameters to be :data.
  - :decrypt: true if the data needs to be decrypted automatically.
- +value+         : value to add in hdata Hash.

return:

raise:

# File lib/core/core_object_params.rb, line 98
def _build_hdata(object_type, new_params, param_obj, param_options, value)
  return unless param_options[:type] == :data

  value_mapping = PrcLib.model.meta_obj.rh_get(object_type, :value_mapping,
                                               param_obj.fpath)

  attr_name = param_obj.key

  # Mapping from Object/data definition
  if value_mapping.is_a?(Hash)
    PrcLib.runtime_fail("'%s.%s': No value mapping for '%s'",
                        object_type, attr_name,
                        value) unless value_mapping.key?(value)
    value = value_mapping[value]
  end

  if param_options[:decrypt].is_a?(TrueClass)
    value = Lorj::SSLCrypt.get_encrypted_value(value, _get_encrypt_key,
                                               attr_name)
  end

  return unless param_options[:mapping]

  # NOTE: if mapping is set, the definition subtree
  # is ignored.
  # if key map to mykey
  # [:section1][subsect][key] = value
  # new_params => [:hdata][mykey] = value
  # not new_params => [:hdata][:section1][subsect][mykey] = value
  new_params[:hdata].rh_set(value, param_options[:mapping])
  nil
end
_build_param(new_params, param_obj, param_options) click to toggle source

internal runtime function for process call Build a process/controller parameter object (ObjectData)

parameters:

- +new_params+        : ObjectData. Parameters ObjectData
- +param_path+        : Symbol. parameter name
- +param_options+     : Hash. parameter options

return:

  • value : return the parameter value or nil if is :CloudObject type.

raise:

# File lib/core/core_object_params.rb, line 145
def _build_param(new_params, param_obj, param_options)
  param_name = param_obj.key

  case param_options[:type]
  when :data
    return _build_data(new_params, param_obj, param_options)
  when :CloudObject
    if param_options[:required] &&
       @object_data.type?(param_name) != :DataObject
      PrcLib.runtime_fail "Object '%s/%s' is not defined. '%s' "\
                           'requirement failed.',
                          self.class, param_name, __callee__
    end
    if @object_data.exist?(param_name)
      new_params.add(@object_data[param_name, :ObjectData])
    else
      Lorj.debug(2, "The optional '%s' was not loaded", param_name)
    end
  else
    PrcLib.runtime_fail("Undefined ObjectData '%s'.", param_options[:type])
  end
  nil
end
_call_controller_map(map_handler, oControlerObject, attr_tree) click to toggle source

internal runtime function for process call Call the mapping method to get the controller attribute data.

parameters:

- +map_handler+    : map array returned by _map_identify_mapping_handler
- +controller_obj+ : Controller object
- +attr_tree+      : Array of attribute tree to get the controller data.

return:

  • controller data.

raise:

# File lib/core/definition_internal.rb, line 131
def _call_controller_map(map_handler, oControlerObject, attr_tree)
  if map_handler[2]
    type = 'controller'
  else
    type = 'process'
  end
  Lorj.debug(4, "Calling '%s.%s' to retrieve/map %s object '%s' data ",
             map_handler[3], map_handler[1], type, attr_tree)

  map_handler[0].call(oControlerObject, attr_tree)
end
_check_required(object_type, sEventType, fname) click to toggle source

internal runtime function for process call Check object needs list, to report missing required data. raise a runtime error if at least, one data is not set. It returns a list “missing objects”.

parameters:

- +object_missing+ : Array of missing object for process caller.
- +attr_name+      : attribute/data name
- +attr_options+   : attribute options
- +fname+          : caller function

return:

  • Array : missing objects.

raise:

  • runtime error if required data is not set. (empty or nil)

# File lib/core/definition_internal.rb, line 194
def _check_required(object_type, sEventType, fname)
  object_missing = []

  attr_paths = PrcLib.model.meta_obj.rh_get(object_type,
                                            :params, :keys)
  PrcLib.runtime_fail("'%s' Object data needs not set. Forgot "\
                      'obj_needs?', object_type) if attr_paths.nil?

  if sEventType == :delete_e &&
     @object_data.type?(object_type) != :DataObject
    object_missing << object_type
  end

  attr_paths.each do |attr_path, attr_options|
    next if attr_options[:for] && !attr_options[:for].include?(sEventType)
    _check_required_attr(object_missing, attr_path, attr_options, fname)
  end
  object_missing
end
_check_required_attr(object_missing, attr_path, attr_options, fname) click to toggle source

internal runtime function Check while the attribute data or object is required, if it is set. raise a runtime error if data is not set. add object in the missing object Array if object is not set.

parameters:

- +object_missing+ : Array of missing object for process caller.
- +attr_path+      : String. Attribute/data path (See KeyPath.fpath)
- +attr_options+   : Hash. Attribute options
- +fname+          : String. Caller function

return:

raise:

  • runtime error if required data is not set. (empty or nil)

# File lib/core/definition_internal.rb, line 230
def _check_required_attr(object_missing, attr_path, attr_options, fname)
  attr_obj = KeyPath.new(attr_path)

  attr_name = attr_obj.key
  case attr_options[:type]
  when :data
    _check_required_attr_data(attr_name, attr_options, fname)
  when :CloudObject
    if attr_options[:required] &&
       @object_data.type?(attr_name) != :DataObject
      object_missing << attr_name
    end
  end
end
_check_required_attr_data(attr_name, attr_options, fname) click to toggle source

internal runtime function Check while the attribute data is required, if data is not set raise a runtime error if not.

parameters:

- +attr_name+    : attribute/data name
- +attr_options+ : attribute options
- +fname+        : caller function

return:

raise:

  • runtime error if required data is not set. (empty or nil)

# File lib/core/definition_internal.rb, line 259
def _check_required_attr_data(attr_name, attr_options, fname)
  default = attr_options.rh_get(:default_value)

  return unless attr_options[:required]

  if attr_options.key?(:extract_from)
    unless @object_data.exist?(attr_options[:extract_from])
      PrcLib.runtime_fail("key '%s' was not extracted from '%s'"\
                          ". '%s' requirement failed.",
                          attr_name, attr_options[:extract_from], fname)
    end
  elsif @config.get(attr_name, default).nil?
    section = Lorj.defaults.get_meta_section(attr_name)
    section = 'runtime' unless section
    PrcLib.runtime_fail("key '%s/%s' is not set. '%s' requirement"\
                        ' failed.', section, attr_name, fname)
  end
end
_export_keys_as_keypath(k, v) click to toggle source

Internal function to determine which section/key to set in export file

It should support Array or String with syntax 'section#key'

# File lib/core/core_import_export.rb, line 186
def _export_keys_as_keypath(k, v)
  rhash_kpath = KeyPath.new(Lorj.data.first_section(k))
  if v.key?(:keys)
    if v[:keys].is_a?(String)
      section, key = Lorj.data.first_section(v[:keys])
      rhash_kpath = KeyPath.new([section, key])
    else
      rhash_kpath = KeyPath.new(v[:keys])
    end
  end
  rhash_kpath
end
_export_processes(processes_options) click to toggle source
# File lib/core/core_import_export.rb, line 199
def _export_processes(processes_options)
  export_data = []
  PrcLib.processes.each do |p|
    next unless p.key?(:process_name) && p.key?(:lib_name)

    next if processes_options[:exclude].is_a?(Array) &&
            processes_options[:exclude].include?(p[:process_name])

    process = {}
    process[:process_module] = p[:process_name]
    process[:lib_name] = p[:lib_name]
    if p.key?(:controller_name)
      process[:controller_name] = p[:controller_name]
    end
    export_data << process if process.length > 0
  end
  export_data
end
_get_account_section(key) click to toggle source
# File lib/core/definition_internal.rb, line 38
def _get_account_section(key)
  return nil if key.nil?
  Lorj.data.first_section(key)[0]
end
_get_controller_params(object_type, sEventType, fname) click to toggle source

internal runtime function for process call Build a controller parameters object (ObjectData)

parameters:

- +object_type+       : object type requiring parameters.
- +sEventType+        : event type used to call the process
- +fname+             : caller function

return:

  • ObjectData : list of data and objects wanted by the process or

    the controller. In case of the controller, hdata
    controller map is also added.

raise:

  • runtime error if required data is not set. (empty or nil)

# File lib/core/core_object_params.rb, line 205
def _get_controller_params(object_type, sEventType, fname)
  _get_object_params(object_type, sEventType, fname, true)
end
_get_encrypt_key() click to toggle source

internal runtime function for process call Get encrypted value hidden by *

Use PrcLib.pdata_path to store/read a '.key' file

parameters:

- +new+       : true to create a new key.

return:

  • value : encrypted key value.

raise:

# File lib/core/core_setup_encrypt.rb, line 114
def _get_encrypt_key
  # Checking key file used to encrypt/decrypt passwords
  key_file = File.join(PrcLib.pdata_path, '.key')
  if !File.exist?(key_file)
    # Need to create a random key.
    entr = Lorj::SSLCrypt.new_encrypt_key

    Lorj.debug(2, "Writing '%s' key file", key_file)
    unless PrcLib.dir_exists?(PrcLib.pdata_path)
      PrcLib.ensure_dir_exists(PrcLib.pdata_path)
    end
    File.open(key_file, 'w+') do |out|
      out.write(Base64.encode64(entr.to_yaml))
    end
  else
    Lorj.debug(2, "Loading '%s' key file", key_file)
    encoded_key = IO.read(key_file)
    entr = YAML.load(Base64.decode64(encoded_key))
  end
  entr
end
_get_encrypted_value_hidden(sDesc, enc_value, entr) click to toggle source

internal runtime function for process call Get encrypted value hidden by *

parameters:

- +sDesc+       : data description
- +default+     : encrypted default value
- +entropy+     : Entropy Hash

return:

  • value : encrypted value.

raise:

# File lib/core/core_setup_encrypt.rb, line 149
def _get_encrypted_value_hidden(sDesc, enc_value, entr)
  return '' if enc_value.nil?
  value_hidden = ''
  begin
    value_hidden = '*' * Lorj::SSLCrypt.get_encrypted_value(enc_value, entr,
                                                            sDesc).length
  rescue => e
    PrcLib.error('Unable to decrypt your %s. You will need to re-enter it.'\
                 '\n%s', sDesc, e.message)
  else
    PrcLib.message("'%s' is already set. If you want to keep it,"\
                   ' just press Enter', sDesc)
  end
  value_hidden
end
_get_meta_data(key) click to toggle source

return Object data meta data.

# File lib/core/definition_internal.rb, line 24
def _get_meta_data(key)
  Lorj.data.auto_section_data(key)
  #  meta_default = Lorj.defaults.get_meta_auto(key)
  #  return nil if meta_default.nil?
  #  meta_default = meta_default.clone

  #  section = Lorj.defaults.get_meta_section(key)
  #  return meta_default if section.nil?
  #  meta = PrcLib.model.meta_data.rh_get(section, key)
  #  return meta_default if meta.nil?

  #  meta_default.merge!(meta)
end
_get_object_params(object_type, sEventType, fname, as_controller, new_params = nil) click to toggle source

internal runtime function for process call Build a process/controller parameters object (ObjectData)

parameters:

- +object_type+       : object type requiring parameters.
- +sEventType+        : event type used to call the process
- +fname+             : caller function
- +as_controller+     : true to store parameters for controller.
                        false to store parameters for process.

return:

  • ObjectData : list of data and objects wanted by the process or

    the controller. In case of the controller, hdata
    controller map is also added.

raise:

  • runtime error if required data is not set. (empty or nil)

# File lib/core/core_object_params.rb, line 227
def _get_object_params(object_type, sEventType, fname, as_controller,
                       new_params = nil)
  # Building handler parameters
  # hdata is built for controller. ie, ObjectData is NOT internal.

  obj_params = PrcLib.model.meta_obj.rh_get(object_type, :params, :keys)

  PrcLib.runtime_fail "%s:'%s' Object data needs not set. Forgot "\
                       'obj_needs?', fname, object_type if obj_params.nil?

  if new_params.nil?
    new_params = _obj_param_init(object_type, sEventType, as_controller)
  end

  _object_params_event(object_type, sEventType).each do |param_obj|
    param_options = obj_params[param_obj.fpath]

    value = _build_param(new_params, param_obj, param_options)

    if as_controller && !value.nil?
      _build_hdata(object_type, new_params, param_obj, param_options, value)
    end
  end
  unless fname == :update_params
    new_params.refresh_set(self, object_type, sEventType, as_controller)
  end
  new_params
end
_get_process_params(object_type, sEventType, fname) click to toggle source

internal runtime function for process call Build a process parameters object (ObjectData)

parameters:

- +object_type+       : object type requiring parameters.
- +sEventType+        : event type used to call the process
- +fname+             : caller function

return:

  • ObjectData : list of data and objects wanted by the process or

    the controller. In case of the controller, hdata
    controller map is also added.

raise:

  • runtime error if required data is not set. (empty or nil)

# File lib/core/core_object_params.rb, line 185
def _get_process_params(object_type, sEventType, fname)
  _get_object_params(object_type, sEventType, fname, false)
end
_map_identify_mapping_handler(object_type) click to toggle source

internal runtime function for process call Get the object controller mapping method and method origin.

If the object is fully managed by the process, ie no controller object is attached to it, the process will own the mapping method.

parameters:

- +object_type+       : object_type to map

return:

  • map_method : return the parameter value.

  • method_name : Name of the map method.

  • is_controller : true if the map method is owned by the controller

    false if the map method is owned by the process.
  • class owner : Class owner of the map method.

raise:

# File lib/core/definition_internal.rb, line 99
def _map_identify_mapping_handler(object_type)
  proc_name = PrcLib.model.meta_obj.rh_get(object_type,
                                           :lambdas, :get_attr_e)

  is_controller = PrcLib.model.meta_obj.rh_get(object_type,
                                               :options, :controller)

  return nil if !proc_name && !is_controller

  if proc_name
    map_handler = [@process.method(proc_name), proc_name, false]
    map_handler << @process.class
    return map_handler
  end

  [@controller.method(:get_attr), :get_attr, true, @controller.class]
end
_mapping_data(object_type, key_obj, object_opts, value) click to toggle source

internal runtime function for process call Do the mapping of the value as defined by obj_needs options: :value_mapping => (Array of attribute tree)

parameters:

- +object_type+ : Object type to get data mapped.
- +key_obj+     : Attribute to map
- +object_opts+ : Attribute options.
- +value+       : Controller value to map.

return:

  • controller data.

raise:

# File lib/core/definition_internal.rb, line 158
def _mapping_data(object_type, key_obj, object_opts, value)
  value_mapping = object_opts.rh_get(:value_mapping, key_obj.fpath)
  if value_mapping && !value.nil?
    value_mapping.each do |map_key, map_value|
      next unless value == map_value
      Lorj.debug(5, "Object '%s' value mapped '%s': '%s' => '%s'",
                 object_type, key_obj.tree,
                 value, map_value)
      return map_key
    end
    PrcLib.runtime_fail("'%s.%s': No controller value mapping for '%s'.",
                        object_type, key_obj.tree, value)
  end

  Lorj.debug(5, "Object '%s' value '%s' extracted: '%s'",
             object_type, key_obj.tree, value)
  value
end
_obj_param_init(object_type, sEventType, as_controller) click to toggle source

Internal runtime function for process call

initialize Object parameters object (ObjectData) And add the current object in parameters in case we called delete_e handler

parameters:

- +object_type+  : ObjectData parameters for this object type.
- +sEventType+   : Event handler called
- +as_controller+: true if this will be a controller parameters object.

returns

- ObjectData: for controller or process
# File lib/core/core_object_params.rb, line 312
def _obj_param_init(object_type, sEventType, as_controller)
  new_params = ObjectData.new(!as_controller)

  if sEventType == :delete_e && @object_data.exist?(object_type)
    new_params.add(@object_data[object_type, :ObjectData])
  end
  new_params
end
_object_params_event(object_type, sEventType, param_type = nil) click to toggle source

Function to provide a list of valid attributes for an event given.

  • args :

    • object_type: object_type

    • event_type : Can be create_e, delete_e, query_e, get_e

    • param_type : Can be nil (default), :data or :CloudObject

  • return:

    • params_obj : List of valid attributes (KeyPath type) for the event given.

# File lib/core/core_object_params.rb, line 266
def _object_params_event(object_type, sEventType, param_type = nil)
  obj_params = PrcLib.model.meta_obj.rh_get(object_type, :params, :keys)

  attrs = []
  obj_params.each do |param_path, param_options|
    next unless _param_event?(param_options, sEventType)

    next if param_type && param_type != param_options[:type]

    attrs << KeyPath.new(param_path)
  end
  attrs
end
_param_event?(param_options, sEventType) click to toggle source

Internal runtime function checking if the attribute is valid with event query

  • args :

    • param_options: Parameter options to use.

    • param_path : Parameter path to check event

    • event_type : Can be create_e, delete_e, query_e, get_e

  • return:

    • true if the attribute name is valid for this event.

    • false otherwise.

# File lib/core/core_object_params.rb, line 291
def _param_event?(param_options, sEventType)
  if param_options.key?(:for)
    return false unless param_options[:for].include?(sEventType)
  end
  true
end
_process_load_dependencies(object_type, proc, handler_name, function_name) click to toggle source
# File lib/core/core_process.rb, line 497
def _process_load_dependencies(object_type, proc, handler_name,
                               function_name)
  missing_obj = _check_required(object_type, handler_name, proc).reverse

  while missing_obj.length > 0
    elem = missing_obj.pop

    if elem == object_type && function_name == :process_delete
      debug(2, "'%s' object is not previously loaded or created.",
            object_type)
      next
    end

    unless process_create(elem)
      PrcLib.runtime_fail "Unable to create Object '%s'", elem
    end

    missing_obj = _check_required(object_type, handler_name, proc).reverse
    PrcLib.runtime_fail "loop detection: '%s' is required but"\
                 " #{function_name}(%s) did not loaded it.",
                        elem, elem if missing_obj.include?(elem)
  end
end
_remove_instant_config(hConfig) click to toggle source
# File lib/core/core_process.rb, line 491
def _remove_instant_config(hConfig)
  return unless hConfig.is_a?(Hash)

  @config.layer_remove :name => hConfig.object_id.to_s
end
_return_map(object_type, oControlerObject) click to toggle source

internal runtime function for process call Get the controller result and map controller object data to lorj object attributes, using controller mapping function.

parameters:

- +object_type+       : object_type to map
- +oControlerObject+  : Controller object

return:

  • value : Hash. return the parameter value.

raise:

# File lib/core/definition_internal.rb, line 56
def _return_map(object_type, oControlerObject)
  return nil if oControlerObject.nil?

  attr_value = {}

  map_handler = _map_identify_mapping_handler(object_type)
  return nil if map_handler.nil?

  object_opts = PrcLib.model.meta_obj.rh_get(object_type)

  maps = object_opts[:returns]
  maps.each do |key, map|
    next unless map

    key_obj = KeyPath.new(key)
    map_obj = KeyPath.new(map)

    value = _call_controller_map(map_handler, oControlerObject,
                                 map_obj.tree)
    value = _mapping_data(object_type, key_obj, object_opts, value)
    attr_value.rh_set(value, key_obj.tree)
  end
  attr_value
end
_setup_attr_already_added?(order_array, data_to_check) click to toggle source

check if a config data is already listed in the setup list at a specific step.

  • Args :

    • order_array : Array of data classified per level/order

    • data_to_check : data to check

  • returns :

    • true if found. false otherwise.

# File lib/core/core_process_setup.rb, line 245
def _setup_attr_already_added?(order_array, data_to_check)
  order_array.each_key do |order_index|
    attributes = order_array[order_index]
    return true unless attributes.index(data_to_check).nil?
  end
  false
end
_setup_data_insert(step, data_to_add) click to toggle source

Internal function to insert the data after several data to ask.

  • Args :

    • step : step structure to update.

    • data_to_add : data to add

    • order_index : last order index of the current step analyzed.

  • Returns:

  • Raises :

# File lib/core/core_process_setup.rb, line 161
def _setup_data_insert(step, data_to_add)
  order_index = _setup_data_where?(step[:order], data_to_add)

  if order_index.nil?
    level_index = step[:order].keys.max
    step[:order][level_index] << data_to_add
    Lorj.debug(3, "%s/L%s/O%s: '%s' added in setup list at position.",
               step[:name], level_index,
               step[:order][level_index].length - 1,
               data_to_add)
    return
  end
  step[:order][order_index[0]].insert(order_index[1], data_to_add)
  Lorj.debug(3, "%s/L%s/O%s: '%s' added in setup list at position.",
             step[:name], order_index[0], order_index[1], data_to_add)
end
_setup_data_position?(order, data_to_check) click to toggle source
# File lib/core/core_process_setup.rb, line 214
def _setup_data_position?(order, data_to_check)
  meta = _get_meta_data(data_to_check)
  return nil if meta.nil?
  return nil unless meta.rh_exist?(:after) || meta.rh_exist?(:before)

  after = meta.rh_get(:after)
  before = meta.rh_get(:before)
  after_index = nil
  before_index = nil

  order.each do |k, attrs|
    attrs.each do |attr_name|
      after_index = [k, attrs.index(attr_name) + 1] if after == attr_name
      before_index = [k, attrs.index(attr_name)] if before == attr_name
    end
  end

  return nil if after_index.nil? && before_index.nil?

  [after_index, before_index, after, before]
end
_setup_data_where?(order, data_to_check) click to toggle source

Internal function to get :after list of data to ask.

  • Args :

    • data_to_check : setup data structure to update.

  • Returns:

    • Array : List of datas which requires to be ask before.

      Empty if not defined.
  • Raises :

# File lib/core/core_process_setup.rb, line 189
def _setup_data_where?(order, data_to_check)
  res = _setup_data_position?(order, data_to_check)

  return nil if res.nil?

  after_index, before_index, after, before = res

  if after_index.nil? || before_index.nil?
    return before_index if after_index.nil?
    return after_index
  end

  if after_index[0] > before_index[0] ||
     (after_index[0] == before_index[0] && after_index[1] > before_index[1])
    PrcLib.warning("Unable to insert '%s' attribute before '%s' (pos %s)"\
                   " and after '%s' (pos %s). "\
                   "'%s' will be added at the end.",
                   data_to_check, before, before_index, after, after_index,
                   data_to_check)
    return nil
  end

  after_index
end
_update_account_meta(data, name) click to toggle source
# File lib/core/core_import_export.rb, line 218
def _update_account_meta(data, name)
  if name.nil? && data.rh_exist?(:account, :name)
    name = data.rh_get(:account, :name)
  end
  controller = data.rh_get(:account, :provider)

  name = nil if name == ''
  controller = nil if controller == ''

  config.ac_update(name, controller) unless name.nil? || controller.nil?
end
get_object(sCloudObj) click to toggle source

Functions available for Process to communicate with the controler Object


# File lib/core/lorj_basedefinition.rb, line 206
def get_object(sCloudObj)
  # ~ return nil unless Lorj::rh_exist?(@CloudData, sCloudObj)
  return nil unless @object_data.exist?(sCloudObj)
  @object_data[sCloudObj, :ObjectData]
  # ~ Lorj::rh_get(@CloudData, sCloudObj)
end