lorj 1.0.9 → 1.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +2 -0
  3. data/example/students_1/process/students.rb +1 -1
  4. data/example/students_1/student_v1.md +2 -0
  5. data/example/students_1/students.rb +2 -1
  6. data/example/students_2/process/students.rb +1 -1
  7. data/example/students_2/students.rb +4 -2
  8. data/example/students_3/controller/yaml_students_def.rb +1 -1
  9. data/example/students_3/process/students.rb +1 -1
  10. data/example/students_3/student_v3.md +5 -3
  11. data/example/students_3/students.rb +5 -3
  12. data/example/students_4/controller/yaml_students_def.rb +1 -1
  13. data/example/students_4/process/students/definition/students.rb +1 -1
  14. data/example/students_4/students.rb +5 -3
  15. data/example/students_5/controller/yaml_students.rb +1 -1
  16. data/example/students_5/process/students.rb +1 -1
  17. data/example/students_5/student_v5.md +4 -4
  18. data/example/students_5/students.rb +8 -7
  19. data/example/yaml_students/students.rb +4 -4
  20. data/lib/core/core.rb +110 -64
  21. data/lib/core/core_internal.rb +110 -15
  22. data/lib/core/core_object_data.rb +4 -4
  23. data/lib/core/core_process_setup.rb +3 -30
  24. data/lib/core/lorj_data.rb +1 -1
  25. data/lib/core/lorj_keypath.rb +3 -1
  26. data/lib/core/process.rb +67 -0
  27. data/lib/lorj/version.rb +2 -1
  28. data/lib/lorj.rb +3 -4
  29. data/lib/lorj_account.rb +6 -5
  30. data/lib/lorj_config.rb +3 -2
  31. data/lib/providers/templates/compute.rb +1 -1
  32. data/lorj-spec/controllers/mock/mock.rb +144 -0
  33. data/lorj-spec/data.yaml +0 -0
  34. data/lorj-spec/process/mock2_process.rb +48 -0
  35. data/lorj-spec/process/mock_process.rb +48 -0
  36. data/lorj-spec/providers/mock2/mock2.rb +0 -0
  37. data/lorj.gemspec +2 -4
  38. data/spec/05_lorj_keypath_spec.rb +78 -0
  39. data/spec/20_lorj_meta_spec.rb +1 -1
  40. data/spec/21_lorj_processes_spec.rb +115 -0
  41. metadata +27 -42
  42. data/lib/core_process/cloud/process/common.rb +0 -60
  43. data/lib/core_process/cloud/process/connection.rb +0 -92
  44. data/lib/core_process/cloud/process/external_network.rb +0 -90
  45. data/lib/core_process/cloud/process/flavor.rb +0 -97
  46. data/lib/core_process/cloud/process/images.rb +0 -99
  47. data/lib/core_process/cloud/process/internet_network.rb +0 -33
  48. data/lib/core_process/cloud/process/internet_server.rb +0 -29
  49. data/lib/core_process/cloud/process/keypairs.rb +0 -332
  50. data/lib/core_process/cloud/process/network.rb +0 -107
  51. data/lib/core_process/cloud/process/public_ip.rb +0 -102
  52. data/lib/core_process/cloud/process/router.rb +0 -267
  53. data/lib/core_process/cloud/process/rules.rb +0 -120
  54. data/lib/core_process/cloud/process/security_groups.rb +0 -120
  55. data/lib/core_process/cloud/process/server.rb +0 -126
  56. data/lib/core_process/cloud/process/server_log.rb +0 -34
  57. data/lib/core_process/cloud/process/subnetwork.rb +0 -96
  58. data/lib/core_process/cloud_process.rb +0 -30
  59. data/lib/prc_base_config.rb +0 -300
  60. data/lib/prc_core_config.rb +0 -1258
  61. data/lib/prc_section_config.rb +0 -90
  62. data/lib/providers/hpcloud/compute.rb +0 -105
  63. data/lib/providers/hpcloud/hpcloud.rb +0 -462
  64. data/lib/providers/hpcloud/network.rb +0 -115
  65. data/lib/providers/hpcloud/security_groups.rb +0 -68
  66. data/lib/providers/openstack/openstack.rb +0 -410
  67. data/lib/providers/openstack/openstack_create.rb +0 -205
  68. data/lib/providers/openstack/openstack_delete.rb +0 -28
  69. data/lib/providers/openstack/openstack_get.rb +0 -39
  70. data/lib/providers/openstack/openstack_process.rb +0 -26
  71. data/lib/providers/openstack/openstack_query.rb +0 -96
  72. data/lib/providers/openstack/openstack_update.rb +0 -35
  73. data/lib/rh.rb +0 -426
  74. data/spec/01_hash_rh_spec.rb +0 -282
  75. data/spec/02_prc_base_config_spec.rb +0 -227
  76. data/spec/03_prc_section_config_spec.rb +0 -196
  77. data/spec/04_prc_core_config_spec.rb +0 -325
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 39a783a3bdefa0193225dbdeeffa904220c3e212
4
- data.tar.gz: b5d15179e5989d20e02dec91bcb5f6fd6cafb530
3
+ metadata.gz: 66366295d6d2bd7fe5249ae3a23204fbf6feb041
4
+ data.tar.gz: 5f82817cfe94a3663ff15a0b2084da299fde4a43
5
5
  SHA512:
6
- metadata.gz: ed18aa7febd8d02e4e5d31bfa9b99407a40f5bc80a97d237bd0696281be2e330756e08d276fb4b77c7e6d90db239e569eb3fea4f661cffd0880ab04a89cb3bc1
7
- data.tar.gz: 3c553c66bd2b48a15e0652c8b18c28ce2bafb4a7c37a47b3fef1712f71dccd761fed8ff992aedf41c8f9e89e9db3a8b230191bd38a6947cf137f9b4575f08ae0
6
+ metadata.gz: d3bc6abf89ad95748426300653103cf351ffcbc49ae1c319e6a77118444ccc819e88c8869cba6dac1a8f43ebd1e1e1720c855477a7ed8808b59d31b356ec2dc4
7
+ data.tar.gz: 8b0d0a9af74d981cb61a0f2330b697edffee5a0451071ba4ef4dc62a04184f91ca5c999b77de4993291c46a10b64b40e1b7be3485f11e2d2a86ea81142607078
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -33,7 +33,7 @@ class Lorj::BaseDefinition # rubocop:disable Style/ClassAndModuleChildren
33
33
  define_obj(:student,
34
34
  # The function to call in the class Students
35
35
  :create_e => :create_student
36
- )
36
+ )
37
37
 
38
38
  obj_needs :data, :student_name, :for => [:create_e]
39
39
  end
@@ -18,6 +18,8 @@ First of all, write your first main. Create a file `example.rb` with following c
18
18
 
19
19
  # Initialize the framework
20
20
  processes = [ File.join(app_path, 'process', 'students.rb')]
21
+ processes = []
22
+ processes << { :process_path => File.join(app_path, 'process', 'students.rb') }
21
23
  student_core = Lorj::Core.new( nil, processes)
22
24
 
23
25
  # Ask the framework to create the object student 'Robert Redford'
@@ -30,7 +30,8 @@ require 'lorj'
30
30
  # PrcLib.core_level = 3 # framework debug levels.
31
31
 
32
32
  # Initialize the framework
33
- processes = [File.join(app_path, 'process', 'students.rb')]
33
+ processes = []
34
+ processes << { :process_path => File.join(app_path, 'process', 'students.rb') }
34
35
 
35
36
  student_core = Lorj::Core.new(nil, processes)
36
37
 
@@ -42,7 +42,7 @@ class Lorj::BaseDefinition # rubocop: disable Style/ClassAndModuleChildren
42
42
  :get_e => :controller_get,
43
43
  # We use predefined call to the controller delete
44
44
  :delete_e => :controller_delete
45
- )
45
+ )
46
46
 
47
47
  obj_needs :data, :student_name, :for => [:create_e], :mapping => :name
48
48
  end
@@ -30,10 +30,12 @@ require 'lorj'
30
30
  # PrcLib.core_level = 3 # framework debug levels.
31
31
 
32
32
  # Initialize the framework
33
- processes = [File.join(app_path, 'process', 'students.rb')]
33
+ processes = []
34
+ processes << { :process_path => File.join(app_path, 'process', 'students.rb'),
35
+ :controller_name => :mock }
34
36
 
35
37
  # byebug if ENV['BYEBUG'] # rubocop: disable Debugger
36
- student_core = Lorj::Core.new(nil, processes, :mock)
38
+ student_core = Lorj::Core.new(nil, processes)
37
39
  # Ask the framework to create the object student 'Robert Redford'
38
40
  student_core.create(:student, :student_name => 'Robert Redford')
39
41
 
@@ -41,7 +41,7 @@ class YamlStudents
41
41
  define_obj(:connection,
42
42
  # Nothing complex to do. So, simply call the controller create.
43
43
  :create_e => :controller_create
44
- )
44
+ )
45
45
 
46
46
  obj_needs :data, :connection_string, :mapping => :file_name
47
47
  undefine_attribute :id # Do not return any predefined ID
@@ -42,7 +42,7 @@ class Lorj::BaseDefinition # rubocop: disable Style/ClassAndModuleChildren
42
42
  :get_e => :controller_get,
43
43
  # We use predefined call to the controller delete
44
44
  :delete_e => :controller_delete
45
- )
45
+ )
46
46
 
47
47
  obj_needs :data, :student_name, :for => [:create_e], :mapping => :name
48
48
  end
@@ -20,9 +20,11 @@ processes = [File.join(app_path, 'process', 'students.rb')]
20
20
  # now we changed from mock to our own controller, located in
21
21
  controller = File.join(app_path, 'controller', 'yaml_students.rb')
22
22
 
23
- # controller/yaml_students.rb
24
- # student_core = Lorj::Core.new(nil, processes, :mock)
25
- student_core = Lorj::Core.new(nil, processes, controller)
23
+ processes = []
24
+ processes << { :process_path => File.join(app_path, 'process', 'students.rb'),
25
+ :controller_path => File.join(app_path, 'controller', 'yaml_students.rb') }
26
+
27
+ student_core = Lorj::Core.new(nil, processes)
26
28
  ```
27
29
 
28
30
  Now, let's write the controller file.
@@ -30,15 +30,17 @@ PrcLib.level = Logger::DEBUG # Printed out to your console.
30
30
  PrcLib.core_level = 3 # framework debug levels.
31
31
 
32
32
  # Initialize the framework
33
- processes = [File.join(app_path, 'process', 'students.rb')]
34
- controller = File.join(app_path, 'controller', 'yaml_students.rb')
33
+ processes = []
34
+ processes << { :process_path => File.join(app_path, 'process', 'students.rb'),
35
+ :controller_path => File.join(app_path, 'controller',
36
+ 'yaml_students.rb') }
35
37
 
36
38
  # now we changed from mock to our own controller, located in
37
39
  # controller/yaml_students.rb
38
40
  # student_core = Lorj::Core.new(nil, processes, :mock)
39
41
  config = Lorj::Config.new
40
42
  config[:connection_string] = '/tmp/students.yaml'
41
- student_core = Lorj::Core.new(config, processes, controller)
43
+ student_core = Lorj::Core.new(config, processes)
42
44
 
43
45
  # Ask the framework to create the object student 'Robert Redford'
44
46
  student_core.create(:student, :student_name => 'Robert Redford')
@@ -41,7 +41,7 @@ class YamlStudents
41
41
  define_obj(:connection,
42
42
  # Nothing complex to do. So, simply call the controller create.
43
43
  :create_e => :controller_create
44
- )
44
+ )
45
45
 
46
46
  obj_needs :data, :connection_string, :mapping => :file_name
47
47
  undefine_attribute :id # Do not return any predefined ID
@@ -30,7 +30,7 @@ class Lorj::BaseDefinition # rubocop: disable Style/ClassAndModuleChildren
30
30
  :get_e => :controller_get,
31
31
  # We use predefined call to the controller delete
32
32
  :delete_e => :controller_delete
33
- )
33
+ )
34
34
 
35
35
  # obj_needs is used to declare parameters to pass to handlers.
36
36
  # :for indicates those parameters to be passed to create_e handler only.
@@ -30,15 +30,17 @@ PrcLib.level = Logger::DEBUG # Printed out to your console.
30
30
  PrcLib.core_level = 3 # framework debug levels.
31
31
 
32
32
  # Initialize the framework
33
- processes = [File.join(app_path, 'process', 'students.rb')]
34
- controller = File.join(app_path, 'controller', 'yaml_students.rb')
33
+ processes = []
34
+ processes << { :process_path => File.join(app_path, 'process', 'students.rb'),
35
+ :controller_path => File.join(app_path, 'controller',
36
+ 'yaml_students.rb') }
35
37
 
36
38
  # now we changed from mock to our own controller, located in
37
39
  # controller/yaml_students.rb
38
40
  # student_core = Lorj::Core.new(nil, processes, :mock)
39
41
  config = Lorj::Config.new
40
42
  config[:connection_string] = '/tmp/students.yaml'
41
- student_core = Lorj::Core.new(config, processes, controller)
43
+ student_core = Lorj::Core.new(config, processes)
42
44
 
43
45
  # Ask the framework to create the object student 'Robert Redford'
44
46
  student_core.create(:student, :student_name => 'Robert Redford')
@@ -70,7 +70,7 @@ class YamlStudents
70
70
  define_obj(:connection,
71
71
  # Nothing complex to do. So, simply call the controller create.
72
72
  :create_e => :controller_create
73
- )
73
+ )
74
74
 
75
75
  obj_needs :data, :connection_string, :mapping => :file_name
76
76
  undefine_attribute :id # Do not return any predefined ID
@@ -149,7 +149,7 @@ module Lorj
149
149
  :query_e => :controller_query,
150
150
  # We use predefined call to the controller delete
151
151
  :delete_e => :controller_delete
152
- )
152
+ )
153
153
 
154
154
  # obj_needs is used to declare parameters to pass to handlers.
155
155
  # :for indicates those parameters to be passed to create_e handler only.
@@ -136,12 +136,12 @@ This is a simple basic translation of `examples/yaml_students/students.rb`
136
136
  # PrcLib.level = Logger::DEBUG # Printed out to your console.
137
137
  # PrcLib.core_level = 3 # framework debug levels. Values between 0 to 5.
138
138
 
139
+ processes = []
140
+ processes << { :process_path => File.join(app_path, 'process', 'students.rb'),
141
+ :controller_path => File.join(app_path, 'controller', 'yaml_students.rb') }
139
142
  # Initialize the framework
140
- hProcesses = [ File.join($APP_PATH, 'process', 'students.rb')]
141
143
 
142
- # You can try with mock instead. uncomment the next line and comment 2 next lines.
143
- #~ oStudentCore = Lorj::Core.new( nil, hProcesses, :mock)
144
- oStudentCore = Lorj::Core.new( nil, hProcesses, File.join($APP_PATH, 'controller', 'yaml_students.rb'))
144
+ oStudentCore = Lorj::Core.new( nil, processes)
145
145
  oStudentCore.Create(:connection, :connection_string => "/tmp/students.yaml")
146
146
 
147
147
  puts ANSI.bold("Create 1st student:")
@@ -50,11 +50,12 @@ config = Lorj::Config.new # Use Simple Config Object
50
50
  # PrcLib.core_level = 5 # framework debug levels.
51
51
 
52
52
  # Initialize the framework
53
- processes = [File.join(app_path, 'process', 'students.rb')]
54
- controller = File.join(app_path, 'controller', 'yaml_students.rb')
55
-
53
+ processes = []
54
+ processes << { :process_path => File.join(app_path, 'process', 'students.rb'),
55
+ :controller_path => File.join(app_path, 'controller',
56
+ 'yaml_students.rb') }
56
57
  # ~ student_core = Lorj::Core.new( config, processes, :mock)
57
- student_core = Lorj::Core.new(config, processes, controller)
58
+ student_core = Lorj::Core.new(config, processes)
58
59
 
59
60
  student_core.create(:connection, :connection_string => '/tmp/students.yaml')
60
61
 
@@ -79,7 +80,7 @@ student_core.create(:student,
79
80
  :first_name => 'Anthony',
80
81
  :last_name => 'Hopkins',
81
82
  :course => 'Art Drama'
82
- )
83
+ )
83
84
  # config[:student_name] = "Anthony Hopkins"
84
85
  # config[:course] = "Art Drama"
85
86
  # student_core.Create(:student)
@@ -90,7 +91,7 @@ student_core.create(:student,
90
91
  :first_name => 'Marilyn',
91
92
  :last_name => 'Monroe',
92
93
  :course => 'Art Drama'
93
- )
94
+ )
94
95
  # replaced the following :
95
96
  # config[:student_name] = "Anthony Hopkins"
96
97
  # student_core.Create(:student)
@@ -101,7 +102,7 @@ student = student_core.create(:student,
101
102
  :first_name => 'Anthony',
102
103
  :last_name => 'Mistake',
103
104
  :course => 'what ever you want!!!'
104
- )
105
+ )
105
106
 
106
107
  puts format("Student created '%s'", student[:attrs])
107
108
 
@@ -31,7 +31,7 @@ if school.query_student(:name => 'Robert Redford').length == 0
31
31
  :first_name => 'Robert',
32
32
  :last_name => 'Redford',
33
33
  :training => 'Art Comedy'
34
- )
34
+ )
35
35
  end
36
36
 
37
37
  puts ANSI.bold('Create 2nd student:')
@@ -40,7 +40,7 @@ if school.query_student(:name => 'Anthony Hopkins').length == 0
40
40
  :first_name => 'Anthony',
41
41
  :last_name => 'Hopkins',
42
42
  :training => 'Art Drama'
43
- )
43
+ )
44
44
  end
45
45
 
46
46
  puts ANSI.bold('Create 3rd student:')
@@ -49,7 +49,7 @@ if school.query_student(:name => 'Marilyn Monroe').length == 0
49
49
  :first_name => 'Marilyn',
50
50
  :last_name => 'Mistake',
51
51
  :training => 'Art Drama'
52
- )
52
+ )
53
53
  end
54
54
 
55
55
  puts ANSI.bold('Create mistake')
@@ -57,7 +57,7 @@ student = school.create_student('Anthony Mistake',
57
57
  :first_name => 'Anthony',
58
58
  :last_name => 'Mistake',
59
59
  :training => 'what ever you want!!!'
60
- )
60
+ )
61
61
 
62
62
  puts format("Student created: '%s'", student)
63
63
 
data/lib/core/core.rb CHANGED
@@ -268,8 +268,8 @@ module Lorj
268
268
  #
269
269
  # * *Args* :
270
270
  # - +oCloudObj+ : Name of the object to initialize.
271
- # - +sAccountName+ : Account file name. If not set, Config[:account_name]
272
- # is used.
271
+ # - +sAccountName+ : Obsolete. You have to load the account data before
272
+ #
273
273
  # If you use this variable, any other runtime config defined
274
274
  # by the Data model will be cleaned before
275
275
  #
@@ -279,40 +279,37 @@ module Lorj
279
279
  # * *Raises* :
280
280
  # No exceptions
281
281
 
282
- def setup(oCloudObj, sAccountName = nil)
282
+ def setup(oCloudObj, _sAccountName = nil)
283
283
  return nil if !oCloudObj || !@core_object
284
- @core_object.process_setup(oCloudObj, sAccountName)
284
+ @core_object.process_setup(oCloudObj)
285
285
  end
286
286
 
287
287
  # Core parameters are:
288
288
  # the_config : Optional. An instance of a configuration system which *HAVE*
289
289
  # to provide get/set/exist?/[]/[]=
290
290
  #
291
- # processClass: Array of string or symbol, or string or symbol. Is the path
292
- # or name of one or more ProcessClass to use.
293
- # This class is dynamically loaded and derived from BaseProcess class.
294
- # It loads the Process class content from a file
295
- # '$CORE_PROCESS_PATH/<process_class>.rb'
296
- # If process_class is a file path, this file will be loaded as a ruby
297
- # include.
298
- #
299
- # <process_class>.rb file name is case sensible and respect RUBY Class
300
- # name convention
301
- #
302
- # controller_class: Optional. string or symbol. Is the path or name of
303
- # ControllerClass to use.
304
- # This class is dynamically loaded and derived from BaseController class.
305
- # It loads the Controler class content from a file
306
- # '$PROVIDER_PATH/<controller_class>.rb'
307
- #
308
- # The provider can redefine partially or totally some processes
309
- # Lorj::Core will load those redefinition from file:
310
- # $PROVIDER_PATH/<controller_class>Process.rb'
311
- #
312
- # <controller_class>.rb or <controller_class>Process.rb file name is case
313
- # sensible and respect RUBY Class name convention
314
- def initialize(the_config = nil, the_process_class = nil,
315
- controller_class = nil)
291
+ # * *Args*:
292
+ # - +Processes+: Array of processes with controller
293
+ # This array, contains a list of process to load and optionnaly a
294
+ # controller.
295
+ #
296
+ # You can define your own process or a process module.
297
+ # The array is structured as follow:
298
+ # - each element contains a Hash with:
299
+ # If you are using a process module, set the following:
300
+ # - :process_module : Name of the process module to load
301
+ #
302
+ # If you are not using a Process module, you need to set the following:
303
+ # - :process_path : Path to a local process code.
304
+ # This path must contains at least 'process' subdir. And if needed
305
+ # a 'controllers' path
306
+ # - :process_name : Name of the local process
307
+ #
308
+ # Optionnally, you can set a controller name to use with the process.
309
+ # - :controller_name: Name of the controller to use.
310
+ # - :controller_path: Path to the controller file.
311
+ #
312
+ def initialize(the_config = nil, processes = nil, controller_class = nil)
316
313
  # Loading ProcessClass
317
314
  # Create Process derived from respectively BaseProcess
318
315
  PrcLib.core_level = 0 if PrcLib.core_level.nil?
@@ -323,65 +320,114 @@ module Lorj
323
320
 
324
321
  model = initialize_model
325
322
 
323
+ # Compatibility with old 'new syntax'
324
+ # `processes` will get an Array of string/symbol or simply a string/symbol
325
+ # `controller_class` is used to define the controller to load.
326
+ # string/symbol
327
+ processes = adapt_core_parameters(processes, controller_class)
328
+
326
329
  # Load Application processes
327
- init_processes(model, the_process_class)
330
+ init_processes(model, processes)
328
331
 
329
332
  PrcLib.runtime_fail 'Lorj::Core: No valid process loaded. '\
330
333
  'Aborting.' if model[:process_class].nil?
331
334
 
332
- # Load Controller and Controller processes.
333
- init_controller(model, controller_class) if controller_class
334
-
335
335
  # Create Core object with the application model loaded
336
336
  # (processes & controller)
337
337
  initialize_core_object(model)
338
338
  PrcLib.model.clear_heap
339
339
  end
340
- end
341
340
 
342
- # This class based on generic Core, defines a Cloud Process to use.
343
- class CloudCore < Core
344
- def initialize(oConfig, sAccount = nil, aProcesses = [])
345
- config_account = init_config(oConfig, sAccount)
341
+ private
346
342
 
347
- process_list = [:cloud_process]
343
+ # This function is used to keep compatibility with old way to load
344
+ # processes and controllers
345
+ # If processes is a Array of Hash => new way
346
+ # otherwise we need to create it.
347
+ def adapt_core_parameters(processes, controller)
348
+ return [] unless processes.is_a?(Array)
348
349
 
349
- controller_mod = config_account.get(:provider)
350
+ return [] if processes.length == 0
351
+ return processes if processes[0].is_a?(Hash)
350
352
 
351
- controller_mod = config_account.get(:provider_name) if controller_mod.nil?
353
+ PrcLib.warning('lorj initialization with Process & controller parameters'\
354
+ ' is obsolete. Read Lorj::Core.new to update it and '\
355
+ 'eliminate this warning')
352
356
 
353
- PrcLib.runtime_fail 'Provider_name not set. Unable to create'\
354
- ' instance CloudCore.' if controller_mod.nil?
357
+ # Declare processes
358
+ processes = processes_as_array(processes)
355
359
 
356
- init_controller_mod(process_list, controller_mod)
360
+ processes_built = []
357
361
 
358
- super(config_account, process_list.concat(aProcesses), controller_mod)
359
- end
362
+ processes.each do |process|
363
+ process = process.to_s if process.is_a?(Symbol)
364
+ a_process = {}
360
365
 
361
- private
366
+ if process.include?('/')
367
+ a_process[:process_path] = process
368
+ a_process[:process_name] = File.basename(process)
369
+ else
370
+ a_process[:process_module] = process
371
+ end
372
+ processes_built << a_process
373
+ end
362
374
 
363
- def init_config(oConfig, sAccount)
364
- if oConfig.is_a?(Lorj::Account)
365
- config_account = oConfig
366
- else
367
- config_account = Lorj::Account.new(oConfig)
375
+ _adapt_with_controller(processes_built, controller)
368
376
 
369
- config_account.ac_load(sAccount) unless sAccount.nil?
370
- end
371
- config_account
377
+ processes_built
372
378
  end
373
379
 
374
- def init_controller_mod(process_list, controller_mod)
375
- # TODO: Support for process full path, instead of predefined one.
376
- controller_process_mod = File.join(PrcLib.controller_path, controller_mod,
377
- controller_mod.capitalize +
378
- 'Process.rb')
379
- if File.exist?(controller_process_mod)
380
- process_list << controller_process_mod
380
+ def _adapt_with_controller(processes_built, controller)
381
+ return if controller.nil?
382
+
383
+ if controller.include?('/')
384
+ processes_built[-1][:controller_path] = controller
385
+ processes_built[-1][:controller_name] = File.basename(controller)
381
386
  else
382
- Lorj.debug(1, format("No Provider process defined. File '%s' not "\
383
- 'found.', controller_process_mod))
387
+ processes_built[-1][:controller_name] = controller
384
388
  end
385
389
  end
386
390
  end
391
+
392
+ module_function
393
+
394
+ # Any Lorj process module will need to declare itself to Lorj
395
+ # with this function.
396
+ #
397
+ # * *args* :
398
+ # - +process_name+: name of the process declared to Lorj. This name must be
399
+ # unique. Otherwise the declaration won't happen.
400
+ #
401
+ # - +path+ : Path where process dir structure are located.
402
+ # at least, it expects to find the process/<name>.rb
403
+ # Each controllers found will be added as well.
404
+ # It must be controllers/<controller_name>/<controller_name>.rb
405
+ # You can change 'controllers' by any name, with :controllers_dir
406
+ #
407
+ # - +properties : Optional.
408
+ # - :controllers_dir : Name of the controllers directory.
409
+ # By default 'controllers'
410
+ #
411
+ # The process will be added in Lorj.processes Hash
412
+ #
413
+ def declare_process(process_name, path, properties = {})
414
+ process_data = Lorj::ProcessResource.new(process_name, path, properties)
415
+
416
+ return nil if process_data.nil?
417
+
418
+ @processes = {} if @processes.nil?
419
+
420
+ return nil if process_data.process.nil?
421
+
422
+ process_name = process_data.name
423
+
424
+ @processes[process_name] = process_data unless @processes.key?(process_name)
425
+
426
+ process_data
427
+ end
428
+
429
+ # Define module data for lorj library configuration
430
+ class << self
431
+ attr_reader :processes
432
+ end
387
433
  end