lorj 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/README.md +39 -579
  4. data/Rakefile +7 -0
  5. data/example/students_1/student_v1.md +115 -0
  6. data/example/students_1/students.rb +8 -2
  7. data/example/students_2/process/students.rb +5 -5
  8. data/example/students_2/student_v2.md +90 -0
  9. data/example/students_2/students.rb +6 -6
  10. data/example/students_3/controller/yaml_students.rb +23 -73
  11. data/example/students_3/controller/yaml_students_code.rb +106 -0
  12. data/example/students_3/controller/yaml_students_def.rb +69 -0
  13. data/example/students_3/process/students.rb +23 -157
  14. data/example/students_3/student_v3.md +283 -0
  15. data/example/students_3/students.rb +26 -83
  16. data/example/students_4/controller/yaml_students.rb +51 -0
  17. data/example/students_4/controller/yaml_students_code.rb +109 -0
  18. data/example/students_4/controller/yaml_students_def.rb +72 -0
  19. data/example/students_4/process/students/code/students.rb +103 -0
  20. data/example/students_4/process/students/definition/students.rb +60 -0
  21. data/example/students_4/process/students.rb +29 -0
  22. data/example/students_4/student_v4.md +191 -0
  23. data/example/students_4/students.rb +65 -0
  24. data/example/students_5/controller/yaml_students.rb +106 -0
  25. data/example/{students_3 → students_5}/controller/yaml_students_controller.rb +5 -3
  26. data/example/students_5/process/students.rb +182 -0
  27. data/example/students_5/student_v5.md +382 -0
  28. data/example/students_5/students.rb +119 -0
  29. data/example/yaml_students/students.rb +1 -1
  30. data/example/yaml_students/yaml_students.rb +102 -23
  31. data/lib/concept.md +3 -3
  32. data/lib/core/core.rb +15 -15
  33. data/lib/core/core_controller.rb +49 -24
  34. data/lib/core/core_internal.rb +2 -2
  35. data/lib/core/core_model.rb +13 -7
  36. data/lib/core/core_object_data.rb +18 -18
  37. data/lib/core/core_object_params.rb +75 -34
  38. data/lib/core/core_process.rb +104 -59
  39. data/lib/core/core_process_setup.rb +11 -11
  40. data/lib/core/core_setup_ask.rb +24 -14
  41. data/lib/core/core_setup_encrypt.rb +17 -15
  42. data/lib/core/core_setup_init.rb +19 -15
  43. data/lib/core/core_setup_list.rb +12 -12
  44. data/lib/core/definition.rb +20 -20
  45. data/lib/core/definition_internal.rb +20 -10
  46. data/lib/core/lorj_basecontroller.rb +8 -8
  47. data/lib/core/lorj_basedefinition.rb +47 -126
  48. data/lib/core/lorj_baseprocess.rb +81 -57
  49. data/lib/core/lorj_data.rb +28 -27
  50. data/lib/core/lorj_keypath.rb +1 -1
  51. data/lib/core_process/cloud/process/flavor.rb +3 -2
  52. data/lib/core_process/cloud/process/keypairs.rb +5 -4
  53. data/lib/core_process/cloud/process/network.rb +4 -3
  54. data/lib/core_process/cloud/process/public_ip.rb +3 -2
  55. data/lib/core_process/cloud/process/rules.rb +7 -6
  56. data/lib/core_process/cloud/process/security_groups.rb +1 -1
  57. data/lib/core_process/cloud/process/server.rb +1 -1
  58. data/lib/core_process/cloud/process/server_log.rb +1 -1
  59. data/lib/core_process/cloud/process/subnetwork.rb +4 -1
  60. data/lib/core_process/cloud_process.rb +1 -1
  61. data/lib/logging.rb +41 -48
  62. data/lib/lorj/version.rb +1 -1
  63. data/lib/lorj.rb +7 -0
  64. data/lib/lorj_account.rb +3 -3
  65. data/lib/lorj_config.rb +1 -1
  66. data/lib/lorj_defaults.rb +222 -26
  67. data/lib/overview.md +120 -0
  68. data/lib/prc.rb +97 -24
  69. data/lib/prc_core_config.rb +134 -52
  70. data/lib/providers/hpcloud/compute.rb +3 -3
  71. data/lib/providers/hpcloud/hpcloud.rb +14 -14
  72. data/lib/providers/hpcloud/network.rb +4 -4
  73. data/lib/providers/hpcloud/security_groups.rb +1 -1
  74. data/lib/providers/mock/mock.rb +3 -3
  75. data/lib/providers/openstack/openstack.rb +12 -12
  76. data/lib/providers/templates/compute.rb +6 -6
  77. data/lib/rh.rb +7 -5
  78. data/spec/04_prc_core_config_spec.rb +52 -0
  79. data/spec/11_lorj_config_spec.rb +1 -1
  80. metadata +21 -3
@@ -133,10 +133,10 @@ module Lorj
133
133
  # nothing
134
134
  def add(oDataObject)
135
135
  # Requires to be a valid framework object.
136
- fail Lorj::PrcError.new,
137
- format("Invalid Framework object type '%s'.",
138
- oDataObject.class) unless oDataObject.is_a?(Lorj::Data)
139
-
136
+ unless oDataObject.is_a?(Lorj::Data)
137
+ PrcLib.runtime_fail "Invalid Framework object type '%s'.",
138
+ oDataObject.class
139
+ end
140
140
  object_data_add(oDataObject)
141
141
  oDataObject.register
142
142
  end
@@ -185,10 +185,10 @@ module Lorj
185
185
  # * *Raises* :
186
186
  # PrcError
187
187
  def exist?(*key) # rubocop: disable Metrics/MethodLength
188
- fail Lorj::PrcError.new, 'ObjectData: key is not list of values '\
189
- '(string/symbol or array)' unless [Array, String,
190
- Symbol].include?(key.class)
191
-
188
+ unless [Array, String, Symbol].include?(key.class)
189
+ PrcLib.runtime_fail 'ObjectData: key is not list of values '\
190
+ '(string/symbol or array)'
191
+ end
192
192
  key = [key] if key.is_a?(Symbol) || key.is_a?(String)
193
193
 
194
194
  key = key.flatten
@@ -200,7 +200,7 @@ module Lorj
200
200
  object_data_exist?(object, key)
201
201
  else
202
202
  # By default true if found key hierarchy
203
- @params.rh_exist?(key)
203
+ @params.rh_exist?(*key)
204
204
  end
205
205
  end
206
206
 
@@ -222,11 +222,12 @@ module Lorj
222
222
  :DataObject if @params[key].type == :object
223
223
  end
224
224
 
225
- # cObj was an old way to get the internal data :object.
226
- # Replaced by get(:object)
227
- # def cobj(*key)
228
- # @params.rh_get(key, :object) if @params.rh_exist?(key, :object)
229
- # end
225
+ def to_s
226
+ str = "-- Lorj::ObjectData --\n"
227
+ str += "Usage internal\n" if @internal
228
+ @params.each { |key, data| str += format("%s:\n%s\n", key, data.to_s) }
229
+ str
230
+ end
230
231
 
231
232
  private
232
233
 
@@ -304,10 +305,9 @@ module Lorj
304
305
  # * *Raises* :
305
306
  # nothing
306
307
  def object_data_delete(obj)
307
- fail Lorj::PrcError.new,
308
- format('ObjectData: delete error. obj is not a'\
309
- " framework data Object. Is a '%s'",
310
- obj.class) unless obj.is_a?(Lorj::Data)
308
+ PrcLib.runtime_fail 'ObjectData: delete error. obj is not a'\
309
+ " framework data Object. Is a '%s'",
310
+ obj.class unless obj.is_a?(Lorj::Data)
311
311
  if obj.type == :list
312
312
  @params.rh_set(nil, :query, obj.object_type?)
313
313
  else
@@ -27,27 +27,33 @@ module Lorj
27
27
  # - +new_params+ : Parameters ObjectData
28
28
  # - +param_object+ : parameter object
29
29
  # - +param_options+ : parameter options
30
- # - +predefined_params+ : predefined parameters.
31
30
  #
32
31
  # *return*:
33
- # - value : return the parameter value.
32
+ # - value : return the parameter value added.
33
+ # The value comes :
34
+ # - from an existing param value if the param_options defines
35
+ # :extract_from
36
+ # - from config layers if exist
37
+ # - from param_option[:default_value] if set
38
+ # OR
39
+ # - nil : if not found
34
40
  #
35
41
  # *raise*:
36
42
  #
37
- def _build_data(new_params, param_obj, param_options, predefined_value)
43
+ def _build_data(new_params, param_obj, param_options)
38
44
  param_name = param_obj.key
39
- value = nil
40
-
41
- default = param_options.rh_get(:default_value)
42
45
 
43
- if param_options[:extract_from]
46
+ unless param_options[:extract_from].nil?
44
47
  value = new_params[param_options[:extract_from]]
48
+ new_params[param_obj.tree] = value
49
+ return value
45
50
  end
46
51
 
47
- return predefined_value if predefined_value && value.nil?
48
-
49
- value = @config.get(param_name, default) if value.nil?
52
+ return nil unless param_options.key?(:default_value) ||
53
+ @config.exist?(param_name)
50
54
 
55
+ default = param_options.rh_get(:default_value)
56
+ value = @config.get(param_name, default)
51
57
  new_params[param_obj.tree] = value
52
58
 
53
59
  value
@@ -76,10 +82,10 @@ module Lorj
76
82
  attr_name = param_obj.key
77
83
 
78
84
  # Mapping from Object/data definition
79
- if value_mapping
80
- runtime_fail("'%s.%s': No value mapping for '%s'",
81
- object_type, attr_name,
82
- value) if Lorj.rhExist?(value_mapping, value) != 1
85
+ if value_mapping.is_a?(Hash)
86
+ PrcLib.runtime_fail("'%s.%s': No value mapping for '%s'",
87
+ object_type, attr_name,
88
+ value) unless value_mapping.key?(value)
83
89
  value = value_mapping[value]
84
90
  end
85
91
 
@@ -102,7 +108,6 @@ module Lorj
102
108
  # - +new_params+ : ObjectData. Parameters ObjectData
103
109
  # - +param_path+ : Symbol. parameter name
104
110
  # - +param_options+ : Hash. parameter options
105
- # - +predefined_params+ : Hash. predefined parameters.
106
111
  #
107
112
  #
108
113
  # *return*:
@@ -110,21 +115,18 @@ module Lorj
110
115
  #
111
116
  # *raise*:
112
117
  #
113
- def _build_param(new_params,
114
- param_obj, param_options, predefined_value)
115
-
118
+ def _build_param(new_params, param_obj, param_options)
116
119
  param_name = param_obj.key
117
120
 
118
121
  case param_options[:type]
119
122
  when :data
120
- return _build_data(new_params, param_obj, param_options,
121
- predefined_value)
123
+ return _build_data(new_params, param_obj, param_options)
122
124
  when :CloudObject
123
125
  if param_options[:required] &&
124
126
  @object_data.type?(param_name) != :DataObject
125
- fail Lorj::PrcError.new,
126
- format("Object '%s/%s' is not defined. '%s' requirement "\
127
- 'failed.', self.class, param_name, fname)
127
+ PrcLib.runtime_fail "Object '%s/%s' is not defined. '%s' "\
128
+ 'requirement failed.',
129
+ self.class, param_name, fname
128
130
  end
129
131
  if @object_data.exist?(param_name)
130
132
  new_params.add(@object_data[param_name, :ObjectData])
@@ -137,6 +139,46 @@ module Lorj
137
139
  nil
138
140
  end
139
141
 
142
+ # internal runtime function for process call
143
+ # Build a process parameters object (ObjectData)
144
+ #
145
+ # *parameters*:
146
+ # - +object_type+ : object type requiring parameters.
147
+ # - +sEventType+ : event type used to call the process
148
+ # - +fname+ : caller function
149
+ #
150
+ # *return*:
151
+ # - ObjectData : list of data and objects wanted by the process or
152
+ # the controller. In case of the controller, hdata
153
+ # controller map is also added.
154
+ #
155
+ # *raise*:
156
+ # - runtime error if required data is not set. (empty or nil)
157
+ #
158
+ def _get_process_params(object_type, sEventType, fname)
159
+ _get_object_params(object_type, sEventType, fname, false)
160
+ end
161
+
162
+ # internal runtime function for process call
163
+ # Build a controller parameters object (ObjectData)
164
+ #
165
+ # *parameters*:
166
+ # - +object_type+ : object type requiring parameters.
167
+ # - +sEventType+ : event type used to call the process
168
+ # - +fname+ : caller function
169
+ #
170
+ # *return*:
171
+ # - ObjectData : list of data and objects wanted by the process or
172
+ # the controller. In case of the controller, hdata
173
+ # controller map is also added.
174
+ #
175
+ # *raise*:
176
+ # - runtime error if required data is not set. (empty or nil)
177
+ #
178
+ def _get_controller_params(object_type, sEventType, fname)
179
+ _get_object_params(object_type, sEventType, fname, true)
180
+ end
181
+
140
182
  # internal runtime function for process call
141
183
  # Build a process/controller parameters object (ObjectData)
142
184
  #
@@ -144,8 +186,8 @@ module Lorj
144
186
  # - +object_type+ : object type requiring parameters.
145
187
  # - +sEventType+ : event type used to call the process
146
188
  # - +fname+ : caller function
147
- # - +as_controller+ : attribute options
148
- # - +predefined_params+ : pre-defined parameters values.
189
+ # - +as_controller+ : true to store parameters for controller.
190
+ # false to store parameters for process.
149
191
  #
150
192
  # *return*:
151
193
  # - ObjectData : list of data and objects wanted by the process or
@@ -155,26 +197,25 @@ module Lorj
155
197
  # *raise*:
156
198
  # - runtime error if required data is not set. (empty or nil)
157
199
  #
158
- def _get_object_params(object_type, sEventType, _fname,
159
- as_controller = false, predefined_params = {})
200
+ def _get_object_params(object_type, sEventType, fname, as_controller)
160
201
  # Building handler parameters
161
202
  # hdata is built for controller. ie, ObjectData is NOT internal.
162
203
 
163
204
  obj_params = PrcLib.model.meta_obj.rh_get(object_type, :params, :keys)
164
205
 
165
- fail Lorj::PrcError.new, "'%s' Object data needs not set. Forgot "\
166
- 'obj_needs?', object_type if obj_params.nil?
206
+ PrcLib.runtime_fail "%s:'%s' Object data needs not set. Forgot "\
207
+ 'obj_needs?', fname, object_type if obj_params.nil?
167
208
 
168
209
  new_params = _obj_param_init(object_type, sEventType, as_controller)
169
210
 
170
- obj_params.each do | param_path, param_options|
171
- next if Lorj.rhExist?(param_options, :for, sEventType) == 2
211
+ obj_params.each do |param_path, param_options|
212
+ if param_options.key?(:for)
213
+ next unless param_options[:for].include?(sEventType)
214
+ end
172
215
 
173
216
  param_obj = KeyPath.new(param_path)
174
- param_name = param_obj.key
175
217
 
176
- value = _build_param(new_params, param_path, param_options,
177
- predefined_params[param_name])
218
+ value = _build_param(new_params, param_obj, param_options)
178
219
 
179
220
  if as_controller && !value.nil?
180
221
  _build_hdata(object_type, new_params, param_obj, param_options, value)
@@ -38,7 +38,9 @@ module Lorj
38
38
  # creation.
39
39
  #
40
40
  # * *Returns* :
41
- # - +Object+ : Lorj::Data object of type +ObjectType+ created.
41
+ # - +Object+ : Lorj::Data object of type +ObjectType+ created.
42
+ # OR
43
+ # - Lorj::Data empty.
42
44
  #
43
45
  # * *Raises* :
44
46
  # - Warning if the create_e process handler did not return any data. (nil)
@@ -49,65 +51,53 @@ module Lorj
49
51
  # data. (nil) - Loop detection.
50
52
  # - Error if the create_e process handler raise an error.
51
53
  #
52
- def process_create(sObjectType, hConfig = {})
53
- # if hConfig.length > 0
54
- # # cleanup runtime data to avoid conflicts between multiple calls
55
- # valid_keys = _identify_data(sObjectType, :create_e)
56
- # valid_keys.each do | sKey|
57
- # value = hConfig.rh_get(sKey)
58
- # @config[sKey] = value if !@config.exist?(sKey) ||
59
- # @config.exist?(sKey) == 'runtime'
60
- # hConfig.rh_set(nil, sKey)
61
- # end
62
- # if hConfig.length > 0
63
- # PrcLib.warning("'%s' has been passed but not declared to '%s'"\
64
- # ' object. Those are ignored until you add it in the'\
65
- # " model definition of '%s'",
66
- # hConfig.keys, sObjectType, sObjectType)
67
- # end
68
- # end
69
-
70
- return nil unless sObjectType
71
-
72
- unless PrcLib.model.meta_obj.rh_exist?(sObjectType)
73
- runtime_fail "%s.Create: '%s' is not a known object type.",
74
- self.class, sObjectType
54
+ def process_create(object_type, hConfig = nil)
55
+ return nil unless object_type
56
+
57
+ _add_instant_config(hConfig)
58
+
59
+ unless PrcLib.model.meta_obj.rh_exist?(object_type)
60
+ PrcLib.runtime_fail "%s.%s: '%s' is not a known object type.",
61
+ self.class, __callee__, object_type
75
62
  end
76
- proc = PrcLib.model.meta_obj.rh_get(sObjectType, :lambdas, :create_e)
63
+ proc = PrcLib.model.meta_obj.rh_get(object_type, :lambdas, :create_e)
77
64
 
78
65
  # Check required parameters
79
66
  _process_load_dependencies(object_type, proc, :create_e, __callee__)
80
67
 
81
68
  # Context: Default object used
82
- @runtime_context[:oCurrentObj] = sObjectType
69
+ @runtime_context[:oCurrentObj] = object_type
83
70
 
84
71
  if proc.nil?
85
72
  # This object is a meta object, without any data.
86
73
  # Used to build other kind of objects.
87
74
  object = Lorj::Data.new
88
- object.set({}, sObjectType) {}
75
+ object.set({}, object_type) {}
89
76
  else
90
77
  # build Function params to pass to the event handler.
91
- params = _get_object_params(sObjectType, :create_e, proc, hConfig)
92
- Lorj.debug(2, "Create Object '%s' - Running '%s'", sObjectType, proc)
78
+ params = _get_process_params(object_type, :create_e, proc)
79
+ Lorj.debug(2, "Create Object '%s' - Running '%s'", object_type, proc)
93
80
 
94
81
  # Call the process function.
95
82
  # At some point, the process will call the controller, via the framework
96
83
  # This controller call via the framework has the role to
97
84
  # create an ObjectData well formatted, with _return_map function
98
85
  # See Definition.connect/create/update/query/get functions (lowercase)
99
- object = @process.method(proc).call(sObjectType, params)
86
+ object = @process.method(proc).call(object_type, params)
100
87
  # return usually is the main object that the process called should
101
88
  # provide.
102
89
  # Save Object if the object has been created by the process, without
103
90
  # controller
104
91
  end
105
92
 
93
+ _remove_instant_config(hConfig)
94
+
106
95
  if object.nil?
107
96
  PrcLib.warning("'%s' has returned no data for object Lorj::Data '%s'!",
108
- proc, sObjectType)
97
+ proc, object_type)
98
+ Lorj::Data.new
109
99
  else
110
- query_cleanup(sObjectType)
100
+ query_cleanup(object_type)
111
101
  @object_data.add(object)
112
102
  end
113
103
  end
@@ -133,12 +123,14 @@ module Lorj
133
123
  # data. (nil) - Loop detection.
134
124
  # - Error if the query_e process handler raise an error.
135
125
  #
136
- def process_delete(object_type, hConfig = {})
126
+ def process_delete(object_type, hConfig = nil)
137
127
  return nil unless object_type
138
128
 
129
+ _add_instant_config(hConfig)
130
+
139
131
  unless PrcLib.model.meta_obj.rh_exist?(object_type)
140
- runtime_fail "%s.Delete: '%s' is not a known object type.",
141
- self.class, object_type
132
+ PrcLib.runtime_fail "%s.%s: '%s' is not a known object type.",
133
+ self.class, __callee__, object_type
142
134
  end
143
135
 
144
136
  proc = PrcLib.model.meta_obj.rh_get(object_type, :lambdas, :delete_e)
@@ -152,11 +144,13 @@ module Lorj
152
144
  @runtime_context[:oCurrentObj] = object_type
153
145
 
154
146
  # build Function params to pass to the event handler.
155
- params = _get_object_params(object_type, :delete_e, proc, hConfig)
147
+ params = _get_process_params(object_type, :delete_e, proc)
156
148
 
157
149
  state = @process.method(proc).call(object_type, params)
158
150
  # return usually is the main object that the process called should provide
159
151
 
152
+ _remove_instant_config(hConfig)
153
+
160
154
  @object_data.delete(object_type) if state
161
155
  end
162
156
 
@@ -204,15 +198,20 @@ module Lorj
204
198
  #
205
199
  # * *Returns* :
206
200
  # Lorj::Data of type :list
201
+ # OR
202
+ # - Lorj::Data empty.
207
203
  #
208
204
  # * *Raises* :
209
205
  #
210
206
  #
211
- def process_query(object_type, hQuery, hConfig = {})
207
+ def process_query(object_type, hQuery, hConfig = nil)
212
208
  return nil unless object_type
209
+
210
+ _add_instant_config(hConfig)
211
+
213
212
  unless PrcLib.model.meta_obj.rh_exist?(object_type)
214
- runtime_fail "%s.Get: '%s' is not a known object type.",
215
- self.class, object_type
213
+ PrcLib.runtime_fail "%s.%s: '%s' is not a known object type.",
214
+ self.class, __callee__, object_type
216
215
  end
217
216
 
218
217
  # Check if we can re-use a previous query
@@ -230,7 +229,7 @@ module Lorj
230
229
  @runtime_context[:oCurrentObj] = object_type
231
230
 
232
231
  # build Function params to pass to the Process Event handler.
233
- params = _get_object_params(object_type, :query_e, proc, hConfig)
232
+ params = _get_process_params(object_type, :query_e, proc)
234
233
 
235
234
  # Call the process function.
236
235
  # At some point, the process will call the controller, via the framework.
@@ -238,10 +237,14 @@ module Lorj
238
237
  # create an ObjectData well formatted, with _return_map function
239
238
  # See Definition.connect/create/update/query/get functions (lowercase)
240
239
  object = @process.method(proc).call(object_type, hQuery, params)
240
+
241
+ _remove_instant_config(hConfig)
242
+
241
243
  # return usually is the main object that the process called should provide
242
244
  if object.nil?
243
245
  PrcLib.warning("'%s' returned no collection of objects Lorj::Data "\
244
246
  "for '%s'", proc, object_type)
247
+ Lorj::Data.new
245
248
  else
246
249
  # Save Object if the object has been created by the process, without
247
250
  # controller
@@ -274,7 +277,9 @@ module Lorj
274
277
  # getting.
275
278
  #
276
279
  # * *Returns* :
277
- # Lorj::Data of type :object
280
+ # - Lorj::Data of type :object
281
+ # OR
282
+ # - Lorj::Data empty.
278
283
  #
279
284
  # * *Raises* :
280
285
  # - Warning if the Config data passed are not required by the meta object
@@ -284,11 +289,14 @@ module Lorj
284
289
  # data. (nil) - Loop detection.
285
290
  # - Error if the get_e process handler raise an error.
286
291
  #
287
- def process_get(object_type, sUniqId, hConfig = {})
292
+ def process_get(object_type, sUniqId, hConfig = nil)
288
293
  return nil unless object_type
294
+
295
+ _add_instant_config(hConfig)
296
+
289
297
  unless PrcLib.model.meta_obj.rh_exist?(object_type)
290
- runtime_fail "$s.Get: '%s' is not a known object type.",
291
- self.class, object_type
298
+ PrcLib.runtime_fail "$s.: '%s' is not a known object type.",
299
+ self.class, __callee__, object_type
292
300
  end
293
301
 
294
302
  proc = PrcLib.model.meta_obj.rh_get(object_type, :lambdas, :get_e)
@@ -302,7 +310,7 @@ module Lorj
302
310
  @runtime_context[:oCurrentObj] = object_type
303
311
 
304
312
  # build Function params to pass to the Process Event handler.
305
- params = _get_object_params(object_type, :get_e, proc, hConfig)
313
+ params = _get_process_params(object_type, :get_e, proc)
306
314
 
307
315
  # Call the process function.
308
316
  # At some point, the process will call the controller, via the framework.
@@ -312,9 +320,15 @@ module Lorj
312
320
  object = @process.method(proc).call(object_type, sUniqId, params)
313
321
  # return usually is the main object that the process called should provide
314
322
 
315
- # Save Object if the object has been created by the process, without
316
- # controller
317
- @object_data.add(object) unless object.nil?
323
+ _remove_instant_config(hConfig)
324
+
325
+ if object.nil?
326
+ PrcLib.warning("'%s' has returned no data for object Lorj::Data '%s'!",
327
+ proc, object_type)
328
+ Lorj::Data.new
329
+ else
330
+ @object_data.add(object)
331
+ end
318
332
  end
319
333
 
320
334
  # Function to execute a update process. This function returns a Lorj::Data
@@ -326,7 +340,9 @@ module Lorj
326
340
  # updating.
327
341
  #
328
342
  # * *Returns* :
329
- # Lorj::Data of type :object
343
+ # - Lorj::Data of type :object
344
+ # OR
345
+ # - Lorj::Data empty.
330
346
  #
331
347
  # * *Raises* :
332
348
  # - Warning if the Config data passed are not required by the meta object
@@ -336,12 +352,14 @@ module Lorj
336
352
  # data. (nil) - Loop detection.
337
353
  # - Error if the get_e process handler raise an error.
338
354
  #
339
- def process_update(object_type, hConfig = {})
355
+ def process_update(object_type, hConfig = nil)
340
356
  return nil unless object_type
341
357
 
358
+ _add_instant_config(hConfig)
359
+
342
360
  unless PrcLib.model.meta_obj.rh_exist?(object_type)
343
- runtime_fail "$s.Update: '%s' is not a known object type.",
344
- self.class, object_type
361
+ PrcLib.runtime_fail "$s.%s: '%s' is not a known object type.",
362
+ self.class, __callee__, object_type
345
363
  end
346
364
 
347
365
  proc = PrcLib.model.meta_obj.rh_get(object_type, :lambdas, :update_e)
@@ -354,14 +372,41 @@ module Lorj
354
372
  @runtime_context[:oCurrentObj] = object_type
355
373
 
356
374
  # build Function params to pass to the event handler.
357
- params = _get_object_params(object_type, :update_e, proc, hConfig)
375
+ params = _get_process_params(object_type, :update_e, proc)
358
376
 
359
377
  object = @process.method(proc).call(object_type, params)
360
378
  # return usually is the main object that the process called should provide
361
379
 
362
- # Save Object if the object has been created by the process, without
363
- # controller
364
- @object_data.add(object) unless object.nil?
380
+ _remove_instant_config(hConfig)
381
+
382
+ if object.nil?
383
+ PrcLib.warning("'%s' has returned no data for object Lorj::Data '%s'!",
384
+ proc, object_type)
385
+ Lorj::Data.new
386
+ else
387
+ @object_data.add(object)
388
+ end
389
+ end
390
+ end
391
+
392
+ # Adding private process core functions.
393
+ class BaseDefinition
394
+ private
395
+
396
+ def _add_instant_config(hConfig)
397
+ return unless hConfig.is_a?(Hash)
398
+
399
+ config = PRC::BaseConfig.new hConfig
400
+ options = { :name => hConfig.object_id.to_s, :config => config,
401
+ :set => false }
402
+
403
+ @config.layer_add PRC::CoreConfig.define_layer(options)
404
+ end
405
+
406
+ def _remove_instant_config(hConfig)
407
+ return unless hConfig.is_a?(Hash)
408
+
409
+ @config.layer_remove :name => hConfig.object_id.to_s
365
410
  end
366
411
 
367
412
  def _process_load_dependencies(object_type, proc, handler_name,
@@ -378,13 +423,13 @@ module Lorj
378
423
  end
379
424
 
380
425
  unless process_create(elem)
381
- runtime_fail "Unable to create Object '%s'", elem
426
+ PrcLib.runtime_fail "Unable to create Object '%s'", elem
382
427
  end
383
428
 
384
429
  missing_obj = _check_required(object_type, handler_name, proc).reverse
385
- runtime_fail "loop detection: '%s' is required but"\
430
+ PrcLib.runtime_fail "loop detection: '%s' is required but"\
386
431
  " #{function_name}(%s) did not loaded it.",
387
- elem, elem if missing_obj.include?(elem)
432
+ elem, elem if missing_obj.include?(elem)
388
433
  end
389
434
  end
390
435
  end
@@ -119,7 +119,7 @@ module Lorj
119
119
  #
120
120
  def process_setup(sObjectType, sAccountName = nil)
121
121
  unless PrcLib.model.meta_obj.rh_exist?(sObjectType)
122
- runtime_fail "Setup: '%s' not a valid object type."
122
+ PrcLib.runtime_fail "Setup: '%s' not a valid object type."
123
123
  end
124
124
 
125
125
  setup_steps = _setup_load
@@ -156,11 +156,11 @@ module Lorj
156
156
  def _setup_data_insert(setup_steps, data_to_add, step, order_index)
157
157
  level_index = 0
158
158
 
159
- _setup_data_after(data_to_add).each do |sAfterKey |
159
+ _setup_data_after(data_to_add).each do |sAfterKey|
160
160
  setup_steps.each_index do |iStepToCheck|
161
161
  order_array = setup_steps[iStepToCheck][:order]
162
162
 
163
- order_array.each_index do | iLevelToCheck |
163
+ order_array.each_index do |iLevelToCheck|
164
164
  data_to_ask = order_array[iLevelToCheck]
165
165
  order_to_check = data_to_ask.index(sAfterKey)
166
166
 
@@ -191,7 +191,7 @@ module Lorj
191
191
  # * *Raises* :
192
192
  #
193
193
  def _setup_data_after(data_to_check)
194
- meta = _get_meta_data(data_to_check)
194
+ meta = _get_meta_data_auto(data_to_check)
195
195
  return [] unless meta.rh_exist?(:after)
196
196
 
197
197
  datas_after = meta[:after]
@@ -206,7 +206,7 @@ module Lorj
206
206
  # - +order_array+ : Array of data classified per level/order
207
207
  # - +data_to_check+ : data to check
208
208
  def _setup_attr_already_added?(order_array, data_to_check)
209
- order_array.each_index do | order_index |
209
+ order_array.each_index do |order_index|
210
210
  attributes = order_array[order_index]
211
211
  return true unless attributes.index(data_to_check).nil?
212
212
  end
@@ -240,7 +240,7 @@ module Lorj
240
240
  return false
241
241
  end
242
242
 
243
- meta = _get_meta_data(attr_name)
243
+ meta = _get_meta_data_auto(attr_name)
244
244
  return false unless meta.is_a?(Hash)
245
245
 
246
246
  ask_step = 0
@@ -250,8 +250,8 @@ module Lorj
250
250
  order_array = setup_steps[ask_step][:order]
251
251
 
252
252
  unless meta[:account].is_a?(TrueClass)
253
- Lorj.debug(2, "'%s' used by '%s' won't be asked during setup."\
254
- ' :account = true not set.', attr_name, object_type)
253
+ Lorj.debug(2, "'%s' won't be asked during setup."\
254
+ ' :account = true not set.', attr_name)
255
255
  return false
256
256
  end
257
257
 
@@ -263,7 +263,7 @@ module Lorj
263
263
  level = _setup_attr_add(order_array[level_index], attr_name, meta,
264
264
  level_index)
265
265
  Lorj.debug(3, "S%s/L%s/%s: '%s' added in setup list. ",
266
- ask_step, level, order_index, attr_name)
266
+ ask_step, level, level_index, attr_name)
267
267
 
268
268
  true
269
269
  end
@@ -300,12 +300,12 @@ module Lorj
300
300
  order_index = meta[:ask_sort]
301
301
  _setup_attr_add_at(level_array, attr_name, order_index)
302
302
  Lorj.debug(3, "S%s/L%s/O%s: '%s' added in setup list. ",
303
- ask_step, level_index, order_index, attr_name)
303
+ meta[:ask_step], level_index, order_index, attr_name)
304
304
  "O#{level_index}"
305
305
  else
306
306
  level_array << attr_name
307
307
  Lorj.debug(3, "S%s/L%s/Last: '%s' added in setup list.",
308
- ask_step, level_index, attr_name)
308
+ meta[:ask_step], level_index, attr_name)
309
309
  'Last'
310
310
  end
311
311
  end