Class: Lorj::ProcessResource

Inherits:
Object
  • Object
show all
Defined in:
lib/core/process.rb

Overview

This class defines a Process module

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, path, props = {}) ⇒ ProcessResource

ProcessResource initialization

Create a ProcessResource Instance with resource data.

  • Args:

    • name : Name of the process

    • path : Process path By default the process path will search for:

      • <name>_process.rb : Main process file

      • <name>/controllers/<controller>/<controller>.rb : controllers list attached to the process ‘name`.

      • <name>/defaults.yaml : defaults process values (under section :defaults)

      • <name>/data.yaml : Process data definition

    You can redefine some defaults, with ‘props` Hash argument.

    • :controllers_dir : Change the name of the controllers directory. Default is ‘controllers`

    • :controllers_path: Change the complete path to search for controllers By default is ‘<name>/controllers`

    • :defaults_file : Use a different file as process defaults. By default is ‘<name>/defaults.yaml`

    • :data_file : Use a different file as process data definition. By default is ‘<name>/data.yaml`

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

  • return:

    • self with at least a process name and a path to it.

      If any data are invalid, the process name will be set to nil.



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/core/process.rb', line 59

def initialize(name, path, props = {})
  name, path, props = _validate_parameters(name, path, props)

  return if name.nil?

  process_path = File.expand_path(File.join(path, 'process',
                                            name + '_process.rb'))

  return nil unless File.exist?(process_path)
  @process = process_path
  @name = name

  controller_dir = 'controllers'
  controller_dir = props[:controllers_dir] if props.key?(:controllers_dir)
  ctrls_path = File.expand_path(File.join(path, 'process', name,
                                          controller_dir))

  _identify_controllers(_get_value(props, :controllers_path, ctrls_path))

  defaults_file = _get_file(props, :defaults_file,
                            File.join(path, 'process',
                                      name, 'defaults.yaml'))
  @defaults_file = defaults_file if defaults_file

  data_file = _get_file(props, :data_file, File.join(path, 'process',
                                                     name, 'data.yaml'))
  @data_file = data_file if data_file

  @lib_name = props[:lib_name] if props.key?(:lib_name)

  self
end

Instance Attribute Details

#controllersObject (readonly)

Returns the value of attribute controllers.



25
26
27
# File 'lib/core/process.rb', line 25

def controllers
  @controllers
end

#data_fileObject (readonly)

Returns the value of attribute data_file.



25
26
27
# File 'lib/core/process.rb', line 25

def data_file
  @data_file
end

#defaults_fileObject (readonly)

Returns the value of attribute defaults_file.



25
26
27
# File 'lib/core/process.rb', line 25

def defaults_file
  @defaults_file
end

#lib_nameObject (readonly)

Returns the value of attribute lib_name.



25
26
27
# File 'lib/core/process.rb', line 25

def lib_name
  @lib_name
end

#nameObject (readonly)

Returns the value of attribute name.



25
26
27
# File 'lib/core/process.rb', line 25

def name
  @name
end

#processObject (readonly)

Returns the value of attribute process.



25
26
27
# File 'lib/core/process.rb', line 25

def process
  @process
end