lorj 0.2.0 → 1.0.0
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +46 -0
- data/Gemfile +15 -15
- data/README.md +22 -17
- data/Rakefile +12 -2
- data/bin/cloud_test.rb +13 -65
- data/example/students_1/process/students.rb +39 -0
- data/example/students_1/students.rb +22 -5
- data/example/students_2/process/students.rb +48 -0
- data/example/students_2/students.rb +39 -16
- data/example/students_3/controller/yaml_students.rb +50 -43
- data/example/students_3/controller/yaml_students_controller.rb +100 -87
- data/example/students_3/process/students.rb +161 -97
- data/example/students_3/students.rb +85 -56
- data/example/yaml_students/students.rb +40 -40
- data/example/yaml_students/yaml_students.rb +103 -90
- data/lib/core/core.rb +356 -696
- data/lib/core/core_controller.rb +227 -0
- data/lib/core/core_internal.rb +339 -0
- data/lib/core/core_model.rb +328 -0
- data/lib/core/core_object_data.rb +330 -0
- data/lib/core/core_object_params.rb +230 -0
- data/lib/core/core_process.rb +391 -0
- data/lib/core/core_process_setup.rb +353 -0
- data/lib/core/core_setup_ask.rb +241 -0
- data/lib/core/core_setup_encrypt.rb +146 -0
- data/lib/core/core_setup_init.rb +229 -0
- data/lib/core/core_setup_list.rb +160 -0
- data/lib/core/definition.rb +647 -469
- data/lib/core/definition_internal.rb +264 -308
- data/lib/core/lorj_basecontroller.rb +95 -0
- data/lib/core/lorj_basedefinition.rb +307 -0
- data/lib/core/lorj_baseprocess.rb +265 -0
- data/lib/core/lorj_data.rb +583 -0
- data/lib/core/lorj_keypath.rb +119 -0
- data/lib/core_process/cloud/process/common.rb +63 -0
- data/lib/core_process/cloud/process/connection.rb +93 -0
- data/lib/core_process/cloud/process/external_network.rb +94 -0
- data/lib/core_process/cloud/process/flavor.rb +99 -0
- data/lib/core_process/cloud/process/images.rb +87 -0
- data/lib/core_process/cloud/process/internet_network.rb +34 -0
- data/lib/core_process/cloud/process/internet_server.rb +30 -0
- data/lib/core_process/cloud/process/keypairs.rb +276 -0
- data/lib/core_process/cloud/process/network.rb +108 -0
- data/lib/core_process/cloud/process/public_ip.rb +100 -0
- data/lib/core_process/cloud/process/router.rb +260 -0
- data/lib/core_process/cloud/process/rules.rb +120 -0
- data/lib/core_process/cloud/process/security_groups.rb +121 -0
- data/lib/core_process/cloud/process/server.rb +127 -0
- data/lib/core_process/cloud/process/server_log.rb +35 -0
- data/lib/core_process/cloud/process/subnetwork.rb +108 -0
- data/lib/core_process/cloud_process.rb +30 -0
- data/lib/logging.rb +298 -0
- data/lib/lorj/version.rb +18 -1
- data/lib/lorj.rb +58 -18
- data/lib/lorj_account.rb +556 -0
- data/lib/lorj_config.rb +468 -0
- data/lib/lorj_defaults.rb +278 -0
- data/lib/prc.rb +136 -104
- data/lib/prc_base_config.rb +285 -0
- data/lib/prc_core_config.rb +878 -0
- data/lib/prc_section_config.rb +57 -0
- data/lib/providers/hpcloud/compute.rb +81 -93
- data/lib/providers/hpcloud/hpcloud.rb +462 -0
- data/lib/providers/hpcloud/network.rb +96 -98
- data/lib/providers/hpcloud/security_groups.rb +41 -40
- data/lib/providers/mock/mock.rb +144 -0
- data/lib/providers/openstack/openstack.rb +45 -0
- data/lib/providers/templates/compute.rb +21 -23
- data/lib/providers/templates/mycloud.rb +72 -0
- data/lib/providers/templates/network.rb +11 -12
- data/lib/rh.rb +339 -0
- data/lorj-spec/defaults.yaml +4 -0
- data/lorj.gemspec +6 -0
- data/spec/00_lorj_log_spec.rb +53 -0
- data/spec/01_hash_rh_spec.rb +243 -0
- data/spec/02_prc_base_config_spec.rb +216 -0
- data/spec/04_prc_core_config_spec.rb +83 -0
- data/spec/11_lorj_config_spec.rb +263 -0
- data/spec/12_lorj_account_spec.rb +181 -0
- metadata +76 -28
- data/Gemfile.lock +0 -37
- data/example/students_1/process/Students.rb +0 -20
- data/example/students_2/process/Students.rb +0 -27
- data/example/students_4/controller/yaml_students.rb +0 -82
- data/example/students_4/controller/yaml_students_controller.rb +0 -141
- data/example/students_4/process/students.rb +0 -112
- data/example/students_4/students.rb +0 -103
- data/lib/core/lorj-basecontroller.rb +0 -90
- data/lib/core/lorj-basedefinition.rb +0 -1139
- data/lib/core/lorj-baseprocess.rb +0 -236
- data/lib/core/lorj-data.rb +0 -567
- data/lib/core/lorj-keypath.rb +0 -115
- data/lib/core_process/CloudProcess.rb +0 -337
- data/lib/core_process/global_process.rb +0 -502
- data/lib/core_process/network_process.rb +0 -605
- data/lib/prc-account.rb +0 -339
- data/lib/prc-config.rb +0 -1030
- data/lib/prc-logging.rb +0 -261
- data/lib/providers/hpcloud/Hpcloud.rb +0 -426
- data/lib/providers/mock/Mock.rb +0 -141
- data/lib/providers/openstack/Openstack.rb +0 -47
- data/lib/providers/templates/core.rb +0 -61
- data/spec/forj-account_spec.rb +0 -75
- data/spec/forj-config_spec.rb +0 -196
data/lib/core/core.rb
CHANGED
|
@@ -15,708 +15,368 @@
|
|
|
15
15
|
# See the License for the specific language governing permissions and
|
|
16
16
|
# limitations under the License.
|
|
17
17
|
|
|
18
|
+
# rubocop: disable Metrics/AbcSize
|
|
19
|
+
|
|
18
20
|
# Module Lorj which contains several classes.
|
|
19
21
|
#
|
|
20
22
|
# Those classes describes :
|
|
21
23
|
# - processes (BaseProcess) : How to create/delete/edit/query object.
|
|
22
|
-
# - controler (BaseControler) : If a provider is defined, define how will do
|
|
23
|
-
#
|
|
24
|
+
# - controler (BaseControler) : If a provider is defined, define how will do
|
|
25
|
+
# object creation/etc...
|
|
26
|
+
# - definition(BaseDefinition): Functions to declare objects, query/data mapping
|
|
27
|
+
# and setup
|
|
24
28
|
# this task to make it to work.
|
|
25
|
-
|
|
26
29
|
module Lorj
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
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
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
#
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
#
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
# - +oCloudObj+ : Name of the object to initialize.
|
|
363
|
-
# - +hConfig+ : Hash of hashes containing data required to initialize the object.
|
|
364
|
-
# If you use this variable, any other runtime config defined
|
|
365
|
-
# by the Data model will be cleaned before
|
|
366
|
-
#
|
|
367
|
-
# * *Returns* :
|
|
368
|
-
# - +Lorj::Data+ : Represents the Object initialized.
|
|
369
|
-
#
|
|
370
|
-
# * *Raises* :
|
|
371
|
-
# No exceptions
|
|
372
|
-
|
|
373
|
-
def GetOrCreate(oCloudObj, hConfig = {})
|
|
374
|
-
return nil if not oCloudObj or not @oCoreObject
|
|
375
|
-
@oCoreObject.Create(oCloudObj, hConfig)
|
|
30
|
+
# This is the main lorj class.
|
|
31
|
+
# It interfaces your main code with the full lorj system as shown in the
|
|
32
|
+
# concept document.
|
|
33
|
+
# It give you access to the lorj model object designed by your process.
|
|
34
|
+
#
|
|
35
|
+
# When you start using it, your main must be as simple as you can, as you will
|
|
36
|
+
# need to move most of your application logic to the process.
|
|
37
|
+
# Your application can have several lorj objects running in your code,
|
|
38
|
+
# depending of your needs.
|
|
39
|
+
#
|
|
40
|
+
# The main things is that you can move most of your process management,
|
|
41
|
+
# usually in your code/modules to be part of the lorj process, make it
|
|
42
|
+
# controller independant, and gains in implementing several controllers to
|
|
43
|
+
# change the way to implement but not the process, you used to build your
|
|
44
|
+
# application!
|
|
45
|
+
#
|
|
46
|
+
# Then, your application contributors can build their own controller and
|
|
47
|
+
# extend your solution!
|
|
48
|
+
#
|
|
49
|
+
# Here an example of creating a CloudServer, using CloudCore
|
|
50
|
+
# (derived from Core).
|
|
51
|
+
# CloudCore introduces lorj predefined CloudProcess used by forj cli.
|
|
52
|
+
#
|
|
53
|
+
# oCloud = Lorj::CloudCore.new(oConfig, 'myhpcloud')
|
|
54
|
+
# oConfig.set(:server_name,'myservername')
|
|
55
|
+
# oCloud.Create(:server)
|
|
56
|
+
#
|
|
57
|
+
# Another basic example (See example directory)
|
|
58
|
+
#
|
|
59
|
+
# oConfig = Lorj::Account.new()
|
|
60
|
+
# oPrc = Lorj::Core.new(oConfig, 'mySqlAccount')
|
|
61
|
+
# oCloud.Create(:student, { :student_name => "Robert Redford"})
|
|
62
|
+
#
|
|
63
|
+
# See BaseProcess to check how you can write a process and what kind of
|
|
64
|
+
# functions are available for your process to be kept controller independant.
|
|
65
|
+
#
|
|
66
|
+
# See BaseController to see how you can write a controller and what kind of
|
|
67
|
+
# functions are available to deal with the implementation API you need to use.
|
|
68
|
+
class Core
|
|
69
|
+
# Public access to a config object.
|
|
70
|
+
# A config object can be any kind of class which should provide at least
|
|
71
|
+
# following functions:
|
|
72
|
+
#
|
|
73
|
+
# - get(*key, default=nil) and [*key] : function to get a value from a key.
|
|
74
|
+
# default is a value to get if not
|
|
75
|
+
# found.
|
|
76
|
+
# - set(*key, value) or [*key, value]= : function to set a value to a key.
|
|
77
|
+
# Ex: From processes, you can set a runtime data with:
|
|
78
|
+
#
|
|
79
|
+
# config.set(key, value)
|
|
80
|
+
#
|
|
81
|
+
# OR
|
|
82
|
+
#
|
|
83
|
+
# config[key] = value
|
|
84
|
+
#
|
|
85
|
+
# - exist?(*key) : function which return false if not
|
|
86
|
+
# found, or any other value if found.
|
|
87
|
+
# Ex: From processes, you can get a data (runtime/account/config.yaml or
|
|
88
|
+
# defaults.yaml) with:
|
|
89
|
+
#
|
|
90
|
+
# config.get(key)
|
|
91
|
+
#
|
|
92
|
+
# OR
|
|
93
|
+
#
|
|
94
|
+
# config[key]
|
|
95
|
+
#
|
|
96
|
+
# For each functions, *key is a list of value, which becomes an array in the
|
|
97
|
+
# function.
|
|
98
|
+
# It should accept to manage the key tree (hash of hashes)
|
|
99
|
+
#
|
|
100
|
+
# Currently lorj comes with Lorj::Config or Lorj::Account.
|
|
101
|
+
# Thoses classes defines at least those 5 functions. And more.
|
|
102
|
+
attr_reader :config
|
|
103
|
+
|
|
104
|
+
# a wrapper to Create call. Use this function for code readibility.
|
|
105
|
+
#
|
|
106
|
+
# * *Args* :
|
|
107
|
+
# - +oCloudObj+ : Name of the object to initialize.
|
|
108
|
+
# - +hConfig+ : Hash of hashes containing data required to initialize
|
|
109
|
+
# the object.
|
|
110
|
+
# If you use this variable, any other runtime config defined
|
|
111
|
+
# by the Data model will be cleaned before
|
|
112
|
+
#
|
|
113
|
+
# * *Returns* :
|
|
114
|
+
# - +Lorj::Data+ : Represents the Object initialized.
|
|
115
|
+
#
|
|
116
|
+
# * *Raises* :
|
|
117
|
+
# No exceptions
|
|
118
|
+
|
|
119
|
+
def connect(oCloudObj, hConfig = {})
|
|
120
|
+
return nil if !oCloudObj || !@core_object
|
|
121
|
+
@core_object.process_create(oCloudObj, hConfig)
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
# Execute the creation process to create the object `oCloudObj`.
|
|
125
|
+
# The creation process can add any kind of complexity to
|
|
126
|
+
# get the a memory representation of the object manipulated during creation
|
|
127
|
+
# process.
|
|
128
|
+
# This means that a creation process can be (non exhaustive list of
|
|
129
|
+
# possibilities)
|
|
130
|
+
# - a connection initialization
|
|
131
|
+
# - an internal memory data structure, like hash, array, ruby object...
|
|
132
|
+
# - a get or create logic
|
|
133
|
+
# - ...
|
|
134
|
+
#
|
|
135
|
+
# * *Args* :
|
|
136
|
+
# - +oCloudObj+ : Name of the object to initialize.
|
|
137
|
+
# - +hConfig+ : Hash of hashes containing data required to initialize
|
|
138
|
+
# the object.
|
|
139
|
+
# If you use this variable, any other runtime config defined
|
|
140
|
+
# by the Data model will be cleaned before
|
|
141
|
+
#
|
|
142
|
+
# * *Returns* :
|
|
143
|
+
# - +Lorj::Data+ : Represents the Object initialized.
|
|
144
|
+
#
|
|
145
|
+
# * *Raises* :
|
|
146
|
+
# No exceptions
|
|
147
|
+
def create(oCloudObj, hConfig = {})
|
|
148
|
+
return nil if !oCloudObj || !@core_object
|
|
149
|
+
@core_object.process_create(oCloudObj, hConfig)
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
# a wrapper to Create call. Use this function for code readibility.
|
|
153
|
+
#
|
|
154
|
+
# * *Args* :
|
|
155
|
+
# - +oCloudObj+ : Name of the object to initialize.
|
|
156
|
+
# - +hConfig+ : Hash of hashes containing data required to initialize
|
|
157
|
+
# the object.
|
|
158
|
+
# If you use this variable, any other runtime config defined
|
|
159
|
+
# by the Data model will be cleaned before
|
|
160
|
+
#
|
|
161
|
+
# * *Returns* :
|
|
162
|
+
# - +Lorj::Data+ : Represents the Object initialized.
|
|
163
|
+
#
|
|
164
|
+
# * *Raises* :
|
|
165
|
+
# No exceptions
|
|
166
|
+
|
|
167
|
+
def get_or_create(oCloudObj, hConfig = {})
|
|
168
|
+
return nil if !oCloudObj || !@core_object
|
|
169
|
+
@core_object.process_create(oCloudObj, hConfig)
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
# Execution of the delete process for the `oCloudObj` object.
|
|
173
|
+
# It requires the object to be loaded in lorj Lorj::Data objects cache.
|
|
174
|
+
# You can use `Create` or `Get` functions to load this object.
|
|
175
|
+
#
|
|
176
|
+
# * *Args* :
|
|
177
|
+
# - +oCloudObj+ : Name of the object to initialize.
|
|
178
|
+
# - +hConfig+ : Hash of hashes containing data required to initialize
|
|
179
|
+
# the object.
|
|
180
|
+
# If you use this variable, any other runtime config defined
|
|
181
|
+
# by the Data model will be cleaned before
|
|
182
|
+
#
|
|
183
|
+
# * *Returns* :
|
|
184
|
+
# - +Lorj::Data+ : Represents the Object initialized.
|
|
185
|
+
#
|
|
186
|
+
# * *Raises* :
|
|
187
|
+
# No exceptions
|
|
188
|
+
|
|
189
|
+
def delete(oCloudObj, hConfig = {})
|
|
190
|
+
return nil if !oCloudObj || !@core_object
|
|
191
|
+
|
|
192
|
+
@core_object.process_delete(oCloudObj, hConfig)
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
# Execution of the Query process for the `oCloudObj` object.
|
|
196
|
+
#
|
|
197
|
+
# * *Args* :
|
|
198
|
+
# - +oCloudObj+ : Name of the object to initialize.
|
|
199
|
+
# - +sQuery+ : Hash representing the query filter.
|
|
200
|
+
# - +hConfig+ : Hash of hashes containing data required to initialize
|
|
201
|
+
# the object.
|
|
202
|
+
# If you use this variable, any other runtime config defined
|
|
203
|
+
# by the Data model will be cleaned before
|
|
204
|
+
#
|
|
205
|
+
# * *Returns* :
|
|
206
|
+
# - +Lorj::Data+ : Represents the Object initialized.
|
|
207
|
+
#
|
|
208
|
+
# * *Raises* :
|
|
209
|
+
# No exceptions
|
|
210
|
+
|
|
211
|
+
def query(oCloudObj, sQuery, hConfig = {})
|
|
212
|
+
return nil if !oCloudObj || !@core_object
|
|
213
|
+
|
|
214
|
+
@core_object.process_query(oCloudObj, sQuery, hConfig)
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
# Execution of the Get process for the `oCloudObj` object.
|
|
218
|
+
#
|
|
219
|
+
# * *Args* :
|
|
220
|
+
# - +oCloudObj+ : Name of the object to initialize.
|
|
221
|
+
# - +sId+ : data representing the ID (attribute :id) of a Lorj::Data
|
|
222
|
+
# object.
|
|
223
|
+
# - +hConfig+ : Hash of hashes containing data required to initialize
|
|
224
|
+
# the object.
|
|
225
|
+
# If you use this variable, any other runtime config defined
|
|
226
|
+
# by the Data model will be cleaned before
|
|
227
|
+
#
|
|
228
|
+
# * *Returns* :
|
|
229
|
+
# - +Lorj::Data+ : Represents the Object initialized.
|
|
230
|
+
#
|
|
231
|
+
# * *Raises* :
|
|
232
|
+
# No exceptions
|
|
233
|
+
|
|
234
|
+
def get(oCloudObj, sId, hConfig = {})
|
|
235
|
+
return nil if !oCloudObj || !@core_object || sId.nil?
|
|
236
|
+
|
|
237
|
+
@core_object.process_get(oCloudObj, sId, hConfig)
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
# Execution of the Update process for the `oCloudObj` object.
|
|
241
|
+
# Usually, the Controller object data is updated by the process
|
|
242
|
+
# (BaseController::set_attr)
|
|
243
|
+
# then it should call a controller_update to really update the data in the
|
|
244
|
+
# controller.
|
|
245
|
+
#
|
|
246
|
+
# * *Args* :
|
|
247
|
+
# - +oCloudObj+ : Name of the object to initialize.
|
|
248
|
+
# - +sId+ : data representing the ID (attribute :id) of a Lorj::Data
|
|
249
|
+
# object.
|
|
250
|
+
# - +hConfig+ : Hash of hashes containing data required to initialize
|
|
251
|
+
# the object.
|
|
252
|
+
# If you use this variable, any other runtime config defined
|
|
253
|
+
# by the Data model will be cleaned before
|
|
254
|
+
#
|
|
255
|
+
# * *Returns* :
|
|
256
|
+
# - +Lorj::Data+ : Represents the Object initialized.
|
|
257
|
+
#
|
|
258
|
+
# * *Raises* :
|
|
259
|
+
# No exceptions
|
|
260
|
+
|
|
261
|
+
def update(oCloudObj, hConfig = {})
|
|
262
|
+
return nil if !oCloudObj || !@core_object
|
|
263
|
+
|
|
264
|
+
@core_object.process_update(oCloudObj, hConfig)
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
# Function used to ask users about setting up his account.
|
|
268
|
+
#
|
|
269
|
+
# * *Args* :
|
|
270
|
+
# - +oCloudObj+ : Name of the object to initialize.
|
|
271
|
+
# - +sAccountName+ : Account file name. If not set, Config[:account_name]
|
|
272
|
+
# is used.
|
|
273
|
+
# If you use this variable, any other runtime config defined
|
|
274
|
+
# by the Data model will be cleaned before
|
|
275
|
+
#
|
|
276
|
+
# * *Returns* :
|
|
277
|
+
# - +Lorj::Data+ : Represents the Object initialized.
|
|
278
|
+
#
|
|
279
|
+
# * *Raises* :
|
|
280
|
+
# No exceptions
|
|
281
|
+
|
|
282
|
+
def setup(oCloudObj, sAccountName = nil)
|
|
283
|
+
return nil if !oCloudObj || !@core_object
|
|
284
|
+
@core_object.process_setup(oCloudObj, sAccountName)
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
# Core parameters are:
|
|
288
|
+
# the_config : Optional. An instance of a configuration system which *HAVE*
|
|
289
|
+
# to provide get/set/exist?/[]/[]=
|
|
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)
|
|
316
|
+
# Loading ProcessClass
|
|
317
|
+
# Create Process derived from respectively BaseProcess
|
|
318
|
+
PrcLib.core_level = 0 if PrcLib.core_level.nil?
|
|
319
|
+
|
|
320
|
+
init_core_config(the_config)
|
|
321
|
+
|
|
322
|
+
model = initialize_model
|
|
323
|
+
|
|
324
|
+
# Load Application processes
|
|
325
|
+
init_processes(model, the_process_class)
|
|
326
|
+
|
|
327
|
+
fail Lorj::PrcError.new, 'Lorj::Core: No valid process loaded. '\
|
|
328
|
+
'Aborting.' if model[:process_class].nil?
|
|
329
|
+
|
|
330
|
+
# Load Controller and Controller processes.
|
|
331
|
+
init_controller(model, controller_class) if controller_class
|
|
332
|
+
|
|
333
|
+
# Create Core object with the application model loaded
|
|
334
|
+
# (processes & controller)
|
|
335
|
+
initialize_core_object(model)
|
|
336
|
+
PrcLib.model.clear_heap
|
|
337
|
+
end
|
|
338
|
+
end
|
|
339
|
+
|
|
340
|
+
# This class based on generic Core, defines a Cloud Process to use.
|
|
341
|
+
class CloudCore < Core
|
|
342
|
+
def initialize(oConfig, sAccount = nil, aProcesses = [])
|
|
343
|
+
config_account = init_config(oConfig, sAccount)
|
|
344
|
+
|
|
345
|
+
process_list = [:CloudProcess]
|
|
346
|
+
|
|
347
|
+
controller_mod = config_account.get(:provider_name)
|
|
348
|
+
fail Lorj::PrcError.new, 'Provider_name not set. Unable to create'\
|
|
349
|
+
' instance CloudCore.' if controller_mod.nil?
|
|
350
|
+
|
|
351
|
+
init_controller_mod(process_list, controller_mod)
|
|
352
|
+
|
|
353
|
+
super(config_account, process_list.concat(aProcesses), controller_mod)
|
|
354
|
+
end
|
|
355
|
+
|
|
356
|
+
private
|
|
357
|
+
|
|
358
|
+
def init_config(oConfig, sAccount)
|
|
359
|
+
if !oConfig.is_a?(Lorj::Account)
|
|
360
|
+
config_account = oConfig
|
|
361
|
+
else
|
|
362
|
+
config_account = Lorj::Account.new(oConfig)
|
|
363
|
+
|
|
364
|
+
config_account.ac_load(sAccount) unless sAccount.nil?
|
|
376
365
|
end
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
#
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
#
|
|
391
|
-
# * *Raises* :
|
|
392
|
-
# No exceptions
|
|
393
|
-
|
|
394
|
-
def Delete(oCloudObj, hConfig = {})
|
|
395
|
-
return nil if not oCloudObj or not @oCoreObject
|
|
396
|
-
|
|
397
|
-
@oCoreObject.Delete(oCloudObj, hConfig)
|
|
398
|
-
end
|
|
399
|
-
|
|
400
|
-
# Execution of the Query process for the `oCloudObj` object.
|
|
401
|
-
#
|
|
402
|
-
# * *Args* :
|
|
403
|
-
# - +oCloudObj+ : Name of the object to initialize.
|
|
404
|
-
# - +sQuery+ : Hash representing the query filter.
|
|
405
|
-
# - +hConfig+ : Hash of hashes containing data required to initialize the object.
|
|
406
|
-
# If you use this variable, any other runtime config defined
|
|
407
|
-
# by the Data model will be cleaned before
|
|
408
|
-
#
|
|
409
|
-
# * *Returns* :
|
|
410
|
-
# - +Lorj::Data+ : Represents the Object initialized.
|
|
411
|
-
#
|
|
412
|
-
# * *Raises* :
|
|
413
|
-
# No exceptions
|
|
414
|
-
|
|
415
|
-
def Query(oCloudObj, sQuery, hConfig = {})
|
|
416
|
-
return nil if not oCloudObj or not @oCoreObject
|
|
417
|
-
|
|
418
|
-
@oCoreObject.Query(oCloudObj, sQuery, hConfig)
|
|
366
|
+
config_account
|
|
367
|
+
end
|
|
368
|
+
|
|
369
|
+
def init_controller_mod(process_list, controller_mod)
|
|
370
|
+
# TODO: Support for process full path, instead of predefined one.
|
|
371
|
+
controller_process_mod = File.join(PrcLib.controller_path, controller_mod,
|
|
372
|
+
controller_mod.capitalize +
|
|
373
|
+
'Process.rb')
|
|
374
|
+
if File.exist?(controller_process_mod)
|
|
375
|
+
process_list << controller_process_mod
|
|
376
|
+
else
|
|
377
|
+
Lorj.debug(1, format("No Provider process defined. File '%s' not "\
|
|
378
|
+
'found.', controller_process_mod))
|
|
419
379
|
end
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
#
|
|
423
|
-
# * *Args* :
|
|
424
|
-
# - +oCloudObj+ : Name of the object to initialize.
|
|
425
|
-
# - +sId+ : data representing the ID (attribute :id) of a Lorj::Data object.
|
|
426
|
-
# - +hConfig+ : Hash of hashes containing data required to initialize the object.
|
|
427
|
-
# If you use this variable, any other runtime config defined
|
|
428
|
-
# by the Data model will be cleaned before
|
|
429
|
-
#
|
|
430
|
-
# * *Returns* :
|
|
431
|
-
# - +Lorj::Data+ : Represents the Object initialized.
|
|
432
|
-
#
|
|
433
|
-
# * *Raises* :
|
|
434
|
-
# No exceptions
|
|
435
|
-
|
|
436
|
-
def Get(oCloudObj, sId, hConfig = {})
|
|
437
|
-
return nil if not oCloudObj or not @oCoreObject or sId.nil?
|
|
438
|
-
|
|
439
|
-
@oCoreObject.Get(oCloudObj, sId, hConfig)
|
|
440
|
-
end
|
|
441
|
-
|
|
442
|
-
# Execution of the Update process for the `oCloudObj` object.
|
|
443
|
-
# Usually, the Controller object data is updated by the process (BaseController::set_attr)
|
|
444
|
-
# then it should call a controller_update to really update the data in the controller.
|
|
445
|
-
#
|
|
446
|
-
# * *Args* :
|
|
447
|
-
# - +oCloudObj+ : Name of the object to initialize.
|
|
448
|
-
# - +sId+ : data representing the ID (attribute :id) of a Lorj::Data object.
|
|
449
|
-
# - +hConfig+ : Hash of hashes containing data required to initialize the object.
|
|
450
|
-
# If you use this variable, any other runtime config defined
|
|
451
|
-
# by the Data model will be cleaned before
|
|
452
|
-
#
|
|
453
|
-
# * *Returns* :
|
|
454
|
-
# - +Lorj::Data+ : Represents the Object initialized.
|
|
455
|
-
#
|
|
456
|
-
# * *Raises* :
|
|
457
|
-
# No exceptions
|
|
458
|
-
|
|
459
|
-
def Update(oCloudObj, hConfig = {})
|
|
460
|
-
return nil if not oCloudObj or not @oCoreObject
|
|
461
|
-
|
|
462
|
-
@oCoreObject.Update(oCloudObj, hConfig)
|
|
463
|
-
end
|
|
464
|
-
|
|
465
|
-
# Function used to ask users about setting up his account.
|
|
466
|
-
#
|
|
467
|
-
# * *Args* :
|
|
468
|
-
# - +oCloudObj+ : Name of the object to initialize.
|
|
469
|
-
# - +sAccountName+ : Account file name. If not set, Config[:account_name] is used.
|
|
470
|
-
# If you use this variable, any other runtime config defined
|
|
471
|
-
# by the Data model will be cleaned before
|
|
472
|
-
#
|
|
473
|
-
# * *Returns* :
|
|
474
|
-
# - +Lorj::Data+ : Represents the Object initialized.
|
|
475
|
-
#
|
|
476
|
-
# * *Raises* :
|
|
477
|
-
# No exceptions
|
|
478
|
-
|
|
479
|
-
def Setup(oCloudObj, sAccountName = nil)
|
|
480
|
-
return nil if not oCloudObj or not @oCoreObject
|
|
481
|
-
@oCoreObject.Setup(oCloudObj, sAccountName)
|
|
482
|
-
end
|
|
483
|
-
end
|
|
484
|
-
|
|
485
|
-
# This class based on generic Core, defines a Cloud Process to use.
|
|
486
|
-
class CloudCore < Core
|
|
487
|
-
def initialize(oConfig, sAccount = nil, aProcesses = [])
|
|
488
|
-
|
|
489
|
-
unless oConfig.is_a?(Lorj::Account)
|
|
490
|
-
oForjAccount = Lorj::Account.new(oConfig)
|
|
491
|
-
unless sAccount.nil?
|
|
492
|
-
oForjAccount.ac_load(sAccount)
|
|
493
|
-
end
|
|
494
|
-
else
|
|
495
|
-
oForjAccount = oConfig
|
|
496
|
-
end
|
|
497
|
-
aProcessList = [:CloudProcess]
|
|
498
|
-
|
|
499
|
-
sControllerMod = oForjAccount.get(:provider_name)
|
|
500
|
-
raise Lorj::PrcError.new(), "Provider_name not set. Unable to create instance CloudCore." if sControllerMod.nil?
|
|
501
|
-
|
|
502
|
-
sControllerProcessMod = File.join(PrcLib.controller_path, sControllerMod, sControllerMod.capitalize + "Process.rb")
|
|
503
|
-
if File.exist?(sControllerProcessMod)
|
|
504
|
-
aProcessList << sControllerProcessMod
|
|
505
|
-
else
|
|
506
|
-
Lorj.debug(1, "No Provider process defined. File '%s' not found." % sControllerProcessMod)
|
|
507
|
-
end
|
|
508
|
-
|
|
509
|
-
super(oForjAccount, aProcessList.concat(aProcesses), sControllerMod)
|
|
510
|
-
end
|
|
511
|
-
end
|
|
512
|
-
|
|
513
|
-
# Represents a list of key/value pairs
|
|
514
|
-
# if the value is a Lorj::Data(data or list), the key will be the Lorj::Data type.
|
|
515
|
-
#
|
|
516
|
-
#
|
|
517
|
-
#
|
|
518
|
-
# Used by
|
|
519
|
-
# - BaseDefinition to get a Lorj::Data cache.
|
|
520
|
-
# - Process create/query/update/delete/get to build the hParams
|
|
521
|
-
# The object behavior is adapted to the process usage
|
|
522
|
-
# By default for Lorj::Data(:object), hParams[aKey] will get or set object attributes
|
|
523
|
-
#
|
|
524
|
-
# - Controller create/query/update/delete/get to build the hParams
|
|
525
|
-
# The object behavior is adapted to the controller usage
|
|
526
|
-
# By default for Lorj::Data(:object), hParams[aKey] will get or set controller object
|
|
527
|
-
#
|
|
528
|
-
class ObjectData
|
|
529
|
-
# Intialize the object. By default, usage is for controller context.
|
|
530
|
-
#
|
|
531
|
-
# * *Args* :
|
|
532
|
-
# - +bInternal+ : Context
|
|
533
|
-
# - true if process context
|
|
534
|
-
# - false if controller context. This is the default value.
|
|
535
|
-
#
|
|
536
|
-
# * *Returns* :
|
|
537
|
-
# - nothing
|
|
538
|
-
#
|
|
539
|
-
# * *Raises* :
|
|
540
|
-
# No exceptions
|
|
541
|
-
def initialize(bInternal = false)
|
|
542
|
-
|
|
543
|
-
@hParams = {}
|
|
544
|
-
@hParams[:hdata] = {} unless bInternal
|
|
545
|
-
@bInternal = bInternal
|
|
546
|
-
end
|
|
547
|
-
|
|
548
|
-
# Get function
|
|
549
|
-
#
|
|
550
|
-
# key can be an array, a string (converted to a symbol) or a symbol.
|
|
551
|
-
#
|
|
552
|
-
# * *Args* :
|
|
553
|
-
# - +key+ : key tree (list of keys)
|
|
554
|
-
# If key[1] == :attrs, get will forcelly use the Lorj::Data object attributes
|
|
555
|
-
# If key[1] == :ObjectData, get will forcelly return the controller object
|
|
556
|
-
# otherwise, get will depends on the context:
|
|
557
|
-
# - controller context: will return the controller object
|
|
558
|
-
# - Process context: will return the Lorj::Data object attributes
|
|
559
|
-
# * *Returns* :
|
|
560
|
-
# value found or nil.
|
|
561
|
-
# * *Raises* :
|
|
562
|
-
# nothing
|
|
563
|
-
def [] (*key)
|
|
564
|
-
|
|
565
|
-
key = key.flatten
|
|
566
|
-
# Return ObjectData Element if asked. Ignore additional keys.
|
|
567
|
-
return @hParams[key[0]] if key[1] == :ObjectData
|
|
568
|
-
|
|
569
|
-
return @hParams if key.length == 0
|
|
570
|
-
|
|
571
|
-
oObject = Lorj::rhGet(@hParams, key[0])
|
|
572
|
-
return nil if oObject.nil?
|
|
573
|
-
|
|
574
|
-
# Return attributes if asked
|
|
575
|
-
return oObject[:attrs, key[2..-1]] if key[1] == :attrs
|
|
576
|
-
|
|
577
|
-
if oObject.is_a?(Lorj::Data)
|
|
578
|
-
if @bInternal
|
|
579
|
-
# params are retrieved in process context
|
|
580
|
-
# By default, if key is detected as a framework object, return its data.
|
|
581
|
-
return oObject[:attrs, key[1..-1]]
|
|
582
|
-
else
|
|
583
|
-
# params are retrieved in controller context
|
|
584
|
-
# By default, if key is detected as a controller object, return its data.
|
|
585
|
-
return oObject[:object, key[1..-1]]
|
|
586
|
-
end
|
|
587
|
-
end
|
|
588
|
-
|
|
589
|
-
# otherwise, simply return what is found in keys hierarchy.
|
|
590
|
-
Lorj::rhGet(@hParams, key)
|
|
591
|
-
end
|
|
592
|
-
|
|
593
|
-
# Functions used to set simple data/Object for controller/process function call.
|
|
594
|
-
# TODO: to revisit this function, as we may consider simple data, as Lorj::Data object
|
|
595
|
-
def []= (*key, value)
|
|
596
|
-
return nil if [:object, :query].include?(key[0])
|
|
597
|
-
Lorj::rhSet(@hParams, value, key)
|
|
598
|
-
end
|
|
599
|
-
|
|
600
|
-
# Add function. Add a Lorj::Data (data or list) to the ObjectData list.
|
|
601
|
-
#
|
|
602
|
-
# key can be an array, a string (converted to a symbol) or a symbol.
|
|
603
|
-
#
|
|
604
|
-
# * *Args* :
|
|
605
|
-
# - +oDataObject+ : Lorj::Data object
|
|
606
|
-
# * *Returns* :
|
|
607
|
-
# Nothing
|
|
608
|
-
# * *Raises* :
|
|
609
|
-
# nothing
|
|
610
|
-
def add(oDataObject)
|
|
611
|
-
# Requires to be a valid framework object.
|
|
612
|
-
raise Lorj::PrcError.new, "Invalid Framework object type '%s'." % oDataObject.class unless oDataObject.is_a?(Lorj::Data)
|
|
613
|
-
|
|
614
|
-
sObjectType = oDataObject.object_type?
|
|
615
|
-
|
|
616
|
-
if oDataObject.type? == :list
|
|
617
|
-
oOldDataObject = Lorj::rhGet(@hParams, :query, sObjectType)
|
|
618
|
-
oOldDataObject.unregister if oOldDataObject
|
|
619
|
-
Lorj::rhSet(@hParams, oDataObject, :query, sObjectType)
|
|
620
|
-
else
|
|
621
|
-
oOldDataObject = Lorj::rhGet(@hParams, sObjectType)
|
|
622
|
-
oOldDataObject.unregister if oOldDataObject
|
|
623
|
-
@hParams[sObjectType] = oDataObject
|
|
624
|
-
end
|
|
625
|
-
oDataObject.register
|
|
626
|
-
end
|
|
627
|
-
|
|
628
|
-
# delete function. delete a Lorj::Data (data or list) from the ObjectData list.
|
|
629
|
-
#
|
|
630
|
-
# key can be an array, a string (converted to a symbol) or a symbol.
|
|
631
|
-
#
|
|
632
|
-
# * *Args* :
|
|
633
|
-
# - +oDataObject+ : Lorj::Data object
|
|
634
|
-
# * *Returns* :
|
|
635
|
-
# Nothing
|
|
636
|
-
# * *Raises* :
|
|
637
|
-
# nothing
|
|
638
|
-
def delete(oObj)
|
|
639
|
-
if oObj.is_a?(Symbol)
|
|
640
|
-
sObjectType = oObj
|
|
641
|
-
oObj = @hParams[sObjectType]
|
|
642
|
-
@hParams[sObjectType] = nil
|
|
643
|
-
else
|
|
644
|
-
raise Lorj::PrcError.new(), "ObjectData: delete error. oObj is not a framework data Object. Is a '%s'" % oObj.class unless oObj.is_a?(Lorj::Data)
|
|
645
|
-
if oObj.type? == :list
|
|
646
|
-
Lorj::rhSet(@hParams, nil, :query, oObj.object_type?)
|
|
647
|
-
else
|
|
648
|
-
sObjectType = oObj.object_type?
|
|
649
|
-
@hParams[sObjectType] = nil
|
|
650
|
-
end
|
|
651
|
-
end
|
|
652
|
-
oObj.unregister unless oObj.nil?
|
|
653
|
-
end
|
|
654
|
-
|
|
655
|
-
# Merge 2 ObjectData.
|
|
656
|
-
#
|
|
657
|
-
# * *Args* :
|
|
658
|
-
# - +hHash+ : Hash of Lorj::Data. But it is possible to have different object type (not Lorj::Data)
|
|
659
|
-
# * *Returns* :
|
|
660
|
-
# hash merged
|
|
661
|
-
# * *Raises* :
|
|
662
|
-
# nothing
|
|
663
|
-
def << (hHash)
|
|
664
|
-
@hParams.merge!(hHash) unless hHash.nil?
|
|
665
|
-
end
|
|
666
|
-
|
|
667
|
-
# check Lorj::Data attributes or object exists. Or check key/value pair existence.
|
|
668
|
-
#
|
|
669
|
-
# * *Args* :
|
|
670
|
-
# - +hHash+ : Hash of Lorj::Data. But it is possible to have different object type (not Lorj::Data)
|
|
671
|
-
# * *Returns* :
|
|
672
|
-
# true/false
|
|
673
|
-
# * *Raises* :
|
|
674
|
-
# PrcError
|
|
675
|
-
def exist?(*key)
|
|
676
|
-
raise Lorj::PrcError.new, "ObjectData: key is not list of values (string/symbol or array)" if not [Array, String, Symbol].include?(key.class)
|
|
677
|
-
|
|
678
|
-
key = [key] if key.is_a?(Symbol) or key.is_a?(String)
|
|
679
|
-
|
|
680
|
-
key = key.flatten
|
|
681
|
-
|
|
682
|
-
oObject = Lorj::rhGet(@hParams, key[0])
|
|
683
|
-
return false if oObject.nil?
|
|
684
|
-
|
|
685
|
-
if oObject.is_a?(Lorj::Data)
|
|
686
|
-
# Return true if ObjectData Element is found when asked.
|
|
687
|
-
return true if key[1] == :ObjectData and oObject.type?(key[0]) == :object
|
|
688
|
-
|
|
689
|
-
# Return true if attritutes or controller object attributes found when asked.
|
|
690
|
-
return oObject.exist?(key[2..-1]) if key[1] == :attrs
|
|
691
|
-
return oObject.exist?(key[1..-1]) if key.length > 1
|
|
692
|
-
true
|
|
693
|
-
else
|
|
694
|
-
# By default true if found key hierarchy
|
|
695
|
-
(Lorj::rhExist?(@hParams, key) == key.length)
|
|
696
|
-
end
|
|
697
|
-
end
|
|
698
|
-
|
|
699
|
-
# Determine the type of object identified by a key. Lorj::Data attributes or object exists. Or check key/value pair existence.
|
|
700
|
-
#
|
|
701
|
-
# * *Args* :
|
|
702
|
-
# - +key+ : Key to check in ObjectData list.
|
|
703
|
-
# * *Returns* :
|
|
704
|
-
# - nil if not found
|
|
705
|
-
# - :data if the key value is simply a data
|
|
706
|
-
# - :DataObject if the key value is a Lorj::Data
|
|
707
|
-
# * *Raises* :
|
|
708
|
-
# PrcError
|
|
709
|
-
|
|
710
|
-
def type?(key)
|
|
711
|
-
return nil if Lorj::rhExist?(@hParams, key) != 1
|
|
712
|
-
:data
|
|
713
|
-
:DataObject if @hParams[key].type?() == :object
|
|
714
|
-
end
|
|
715
|
-
|
|
716
|
-
def cObj(*key)
|
|
717
|
-
Lorj::rhGet(@hParams, key, :object) if Lorj::rhExist?(@hParams, key, :object) == 2
|
|
718
|
-
end
|
|
719
|
-
|
|
720
|
-
end
|
|
721
|
-
|
|
380
|
+
end
|
|
381
|
+
end
|
|
722
382
|
end
|