Module: Lorj

Defined in:
lib/lorj.rb,
lib/core/core.rb,
lib/lorj_meta.rb,
lib/lorj/compat.rb,
lib/lorj_config.rb,
lib/core/process.rb,
lib/lorj/version.rb,
lib/lorj_account.rb,
lib/lorj_account.rb,
lib/lorj_account.rb,
lib/lorj_account.rb,
lib/lorj_defaults.rb,
lib/core/lorj_data.rb,
lib/core/core_model.rb,
lib/core/definition.rb,
lib/compat/lorj_meta.rb,
lib/core/core_process.rb,
lib/core/lorj_keypath.rb,
lib/core/core_internal.rb,
lib/core/core_setup_ask.rb,
lib/compat/1.8/lorj_meta.rb,
lib/core/core_controller.rb,
lib/core/core_setup_init.rb,
lib/core/core_setup_list.rb,
lib/core/compat/lorj_data.rb,
lib/core/core_object_data.rb,
lib/core/lorj_baseprocess.rb,
lib/core/core_import_export.rb,
lib/core/core_object_params.rb,
lib/core/core_process_setup.rb,
lib/core/core_setup_encrypt.rb,
lib/core/definition_internal.rb,
lib/core/lorj_basecontroller.rb,
lib/core/lorj_basedefinition.rb,
lib/core/compat/1.8/lorj_data.rb,
lib/core/compat/core_object_data.rb,
lib/core/compat/1.8/core_object_data.rb

Overview

© Copyright 2014 Hewlett-Packard Development Company, L.P.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Defined Under Namespace

Modules: DataRubySpec, MetaRubySpec, ObjectDataRubySpec, SSLCrypt Classes: Account, AccountConfig, Accounts, BaseController, BaseDefinition, BaseProcess, Config, Core, Data, Defaults, ERBConfig, KeyPath, MetaAppConfig, Model, ObjectData, PrcError, ProcessResource

Constant Summary collapse

VERSION =
'1.0.17'
DATE =
'2015-06-26'

Class Method Summary collapse

Class Method Details

.account_import(key, import_data, name = nil) ⇒ Object

Function to import an encrypted Hash as a Lorj Account.

The encrypted Hash will be decrypted by the key provided. The content of the hash will be stored in the ‘account’ layer of config.

For details on how import work, look in #account_data_import

  • Args :

    • key : key to use to decrypt the ‘enc_hash’.

    • import_data : import data. This data is structured as follow:

      • :enc_data : The encrypted account data.

      • :processes: Array or models + controllers to load.

    • name : Optional. Name of the account.

  • returns:

    • core : Core object, with loaded model, created during the import.

  • Raises : No exceptions



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/core/core_import_export.rb', line 40

def self.(key, import_data, name = nil)
  import_data = YAML.load(import_data)
  hash = Lorj::SSLCrypt.get_encrypted_value(import_data[:enc_data], key,
                                            'Encrypted account data')

  data = YAML.load(hash)

  processes = import_data[:processes]

  processes.each do |p|
    next unless p.key?(:process_module)

    PrcLib.debug("Loading module '#{p[:process_module]}' from GEM lib '%s'",
                 p[:lib_name])
    begin
      require "#{p[:lib_name]}"
    rescue => e
      PrcLib.error("Unable to load module '#{p[:process_module]}'\n%s", e)
    end
  end

  core = Lorj::Core.new(Lorj::Account.new, processes)
  core.(data, name)

  core
end

.data(data = nil) ⇒ Object

Lorj::defaults exposes the application defaults and Config Lorj metadata.

You can set the Application layer of meta data, replacing load from defaults.yaml

  • Args

    • data : Optionnal initialized Application layer meta data.



754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
# File 'lib/lorj_meta.rb', line 754

def data(data = nil)
  return @metadata unless @metadata.nil?

  unless data.is_a?(Hash)
    data = {}
    # TODO: Replace load from defaults.yaml to a dedicated meta file def.
    if Lorj.defaults.data.key?(:setup)
      data[:setup] = Lorj.defaults.data[:setup]
      Lorj.defaults.data.delete(:setup)
    end
    if Lorj.defaults.data.key?(:sections)
      data[:sections] = Lorj.defaults.data[:sections]
      Lorj.defaults.data.delete(:sections)
    end
  end
  @metadata = Lorj::MetaAppConfig.new data

  @metadata
end

.debug(iLevel, sMsg, *p) ⇒ Object

Internal Lorj function to debug lorj.

  • Args :

    • iLevel : value between 1 to 5. Setting 5 is the most verbose!

    • sMsg : Array of string or symbols. keys tree to follow and check

      existence in yVal.
      
  • Returns :

    • nothing

  • Raises : No exceptions



73
74
75
76
77
78
79
# File 'lib/lorj.rb', line 73

def self::debug(iLevel, sMsg, *p)
  if iLevel <= PrcLib.core_level
    message = format('-%s- %s', iLevel, sMsg)

    PrcLib.debug(message, *p)
  end
end

.declare_process(process_name, path, properties = {}) ⇒ Object

Any Lorj process module will need to declare itself to Lorj with this function.

  • args :

    • process_name: name of the process declared to Lorj. This name must be unique. Otherwise the declaration won’t happen.

    • path : Path where process dir structure are located. at least, it expects to find the process/<name>.rb Each controllers found will be added as well. It must be controllers/<controller_name>/<controller_name>.rb You can change ‘controllers’ by any name, with :controllers_dir

    • +properties : required.

      • :controllers_dir : Name of the controllers directory. By default ‘controllers’

      • :lib_name : name of the gem library declaring the process.

The process will be added in Lorj.processes Hash


485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
# File 'lib/core/core.rb', line 485

def declare_process(process_name, path, properties = {})
  unless properties.is_a?(Hash) && properties[:lib_name].is_a?(String)
    puts("Lorj: process module error: '#{__method__}"\
         "('#{process_name}', '#{path}', #{properties})' requires :lib_name"\
         "\nat line #{caller[0]}")
    return nil
  end
  process_data = Lorj::ProcessResource.new(process_name, path, properties)

  if process_data.nil?
    puts("Lorj: process module error: '#{process_name}' fails to be "\
         "declared:\n"\
         "process_name: '#{process_name}'\n"\
         "path        : '#{path}'\n"\
         "properties  : #{properties.to_yaml}")
    return nil
  end

  @processes = {} if @processes.nil?

  if process_data.process.nil?
    puts("Lorj: process module error: process failure:\n"\
         "process_name: '#{process_name}'\n"\
         "path        : '#{path}'\n"\
         "properties  : #{properties.to_yaml}")
    return nil
  end

  process_name = process_data.name

  @processes[process_name] = process_data unless @processes.key?(process_name)

  process_data
end

.defaultsObject

Lorj::defaults exposes the application defaults and Config Lorj metadata.



272
273
274
275
276
277
278
279
# File 'lib/lorj_defaults.rb', line 272

def defaults
  return @defaults unless @defaults.nil?
  @defaults = Defaults.new

  @defaults.load

  @defaults
end

.processesObject



520
521
522
523
# File 'lib/core/core.rb', line 520

def processes
  @processes = {} if @processes.nil?
  @processes
end