lorj 1.0.18 → 1.0.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/lib/core/core.rb +28 -0
- data/lib/core/core_controller.rb +48 -1
- data/lib/core/core_import_export.rb +18 -3
- data/lib/core/core_process.rb +86 -8
- data/lib/core/definition.rb +3 -1
- data/lib/core/lorj_basecontroller.rb +21 -0
- data/lib/core/lorj_basedefinition.rb +1 -0
- data/lib/core/lorj_baseprocess.rb +10 -0
- data/lib/core/lorj_data.rb +35 -6
- data/lib/lorj/version.rb +2 -2
- data/spec/06_lorj_object_data_spec.rb +3 -0
- data/spec/07_lorj_data_spec.rb +99 -0
- data/spec/31_lorj_importexport_spec.rb +14 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ddea5ea2faad1ac6719e6d91b2722652a2ce806
|
4
|
+
data.tar.gz: 07cac35aa926dd66e0c4a4d90f45e840d457b703
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e78441229d526d9843c65d2b3c7d2eab639f1245b67fa0943302cf361fe4286a8a36bcf1ffcae39edfa0debaa0f156b91547c963de10fff4c20ff048b576a1b
|
7
|
+
data.tar.gz: 5ec21fe303f470f806661e494ff9bf8940151207427d140249ea64f3687bbb37fb16503dd36675c65623a9d853775fae1957e48f3f1cd841ad5f22a46a37ac56
|
data/.rubocop.yml
CHANGED
data/lib/core/core.rb
CHANGED
@@ -272,6 +272,34 @@ module Lorj
|
|
272
272
|
@core_object.process_update(oCloudObj, hConfig)
|
273
273
|
end
|
274
274
|
|
275
|
+
# Execution of the Update process for the `oCloudObj` object.
|
276
|
+
# Usually, the Controller object data is updated by the process
|
277
|
+
# (BaseController::set_attr)
|
278
|
+
# then it should call a controller_update to really update the data in the
|
279
|
+
# controller.
|
280
|
+
#
|
281
|
+
# * *Args* :
|
282
|
+
# - +oCloudObj+ : Name of the object to initialize.
|
283
|
+
# - +sId+ : data representing the ID (attribute :id) of a Lorj::Data
|
284
|
+
# object.
|
285
|
+
# - +hConfig+ : Hash of hashes containing data required to initialize
|
286
|
+
# the object.
|
287
|
+
# If you use this variable, any other runtime config defined
|
288
|
+
# by the Data model will be cleaned before
|
289
|
+
#
|
290
|
+
# * *Returns* :
|
291
|
+
# - +Lorj::Data+ : Represents the Object initialized.
|
292
|
+
#
|
293
|
+
# * *Raises* :
|
294
|
+
# No exceptions
|
295
|
+
|
296
|
+
def refresh(object)
|
297
|
+
return false unless object.is_a?(Lorj::Data) && !object.empty? &&
|
298
|
+
object.type == :object
|
299
|
+
|
300
|
+
@core_object.process_update(object)
|
301
|
+
end
|
302
|
+
|
275
303
|
# Function used to ask users about setting up his account.
|
276
304
|
#
|
277
305
|
# * *Args* :
|
data/lib/core/core_controller.rb
CHANGED
@@ -34,6 +34,7 @@ module Lorj
|
|
34
34
|
:create_e, :connect)
|
35
35
|
controller_obj = @controller.connect(sObjectType, controller_params)
|
36
36
|
data_obj = Lorj::Data.new
|
37
|
+
data_obj.base = self
|
37
38
|
data_obj.set(controller_obj, sObjectType) do |sObjType, oObject|
|
38
39
|
begin
|
39
40
|
_return_map(sObjType, oObject)
|
@@ -60,6 +61,7 @@ module Lorj
|
|
60
61
|
:create_e, :create)
|
61
62
|
controller_obj = @controller.create(sObjectType, controller_params)
|
62
63
|
data_obj = Lorj::Data.new
|
64
|
+
data_obj.base = self
|
63
65
|
data_obj.set(controller_obj, sObjectType) do |sObjType, oObject|
|
64
66
|
begin
|
65
67
|
_return_map(sObjType, oObject)
|
@@ -116,6 +118,7 @@ module Lorj
|
|
116
118
|
|
117
119
|
controller_obj = @controller.get(sObjectType, sUniqId, controller_params)
|
118
120
|
data_obj = Lorj::Data.new
|
121
|
+
data_obj.base = self
|
119
122
|
data_obj.set(controller_obj, sObjectType) do |sObjType, oObject|
|
120
123
|
begin
|
121
124
|
_return_map(sObjType, oObject)
|
@@ -160,6 +163,7 @@ module Lorj
|
|
160
163
|
controller_params)
|
161
164
|
|
162
165
|
data_obj = Lorj::Data.new :list
|
166
|
+
data_obj.base = self
|
163
167
|
data_obj.set(controller_obj,
|
164
168
|
sObjectType, hQuery) do |sObjType, key|
|
165
169
|
begin
|
@@ -188,7 +192,7 @@ module Lorj
|
|
188
192
|
#
|
189
193
|
# returns:
|
190
194
|
# - The controller must return true to inform about the real deletion
|
191
|
-
def controller_update(sObjectType, params =
|
195
|
+
def controller_update(sObjectType, params = nil)
|
192
196
|
_add_instant_config(params)
|
193
197
|
|
194
198
|
# Need to detect data updated and update the Controler object with the
|
@@ -240,5 +244,48 @@ module Lorj
|
|
240
244
|
|
241
245
|
is_done
|
242
246
|
end
|
247
|
+
|
248
|
+
# controller_refresh call lorj framework to execute a controller refresh
|
249
|
+
# task
|
250
|
+
#
|
251
|
+
# The controller must respect the following rule:
|
252
|
+
# - If the refresh was unsuccessful, due to errors, the original object
|
253
|
+
# should be kept intact.
|
254
|
+
# - A boolean should be return to inform that therefresh was executed
|
255
|
+
# successfully or not.
|
256
|
+
#
|
257
|
+
# * *parameters:*
|
258
|
+
# - +object_type+: Lorj object type to use for the refresh.
|
259
|
+
# - +object+ : object to refresh.
|
260
|
+
#
|
261
|
+
# * *returns*:
|
262
|
+
# - boolean: true if refresh was executed successfully.
|
263
|
+
# false otherwise.
|
264
|
+
#
|
265
|
+
def controller_refresh(sObjectType, data_obj)
|
266
|
+
return false unless data_obj.is_a?(Lorj::Data) && !data_obj.empty?
|
267
|
+
|
268
|
+
controller_obj = data_obj[:object]
|
269
|
+
|
270
|
+
is_refreshed = @controller.refresh(sObjectType, controller_obj)
|
271
|
+
|
272
|
+
PrcLib.runtime_fail "Controller function 'refresh' must return true or "\
|
273
|
+
"false. Class returned: '%s'",
|
274
|
+
is_refreshed.class unless is_refreshed.boolean?
|
275
|
+
|
276
|
+
Lorj.debug(1, '%s.%s - refreshed.',
|
277
|
+
@process.class, sObjectType) if is_refreshed
|
278
|
+
|
279
|
+
data_obj.set(controller_obj, sObjectType) do |sObjType, an_object|
|
280
|
+
begin
|
281
|
+
_return_map(sObjType, an_object)
|
282
|
+
rescue => e
|
283
|
+
PrcLib.runtime_fail 'update %s.%s : %s',
|
284
|
+
@process.class, sObjectType, e.message
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
is_refreshed
|
289
|
+
end
|
243
290
|
end
|
244
291
|
end
|
@@ -164,12 +164,11 @@ module Lorj
|
|
164
164
|
data = config[k]
|
165
165
|
end
|
166
166
|
|
167
|
-
|
168
|
-
rhash_tree = v[:keys] if v.key?(:keys)
|
167
|
+
rhash_kpath = _export_keys_as_keypath(k, v)
|
169
168
|
if !data_def.nil? && data_def[:encrypted].is_a?(TrueClass)
|
170
169
|
data = Lorj::SSLCrypt.get_encrypted_value(data, entr, data_def[:desc])
|
171
170
|
end
|
172
|
-
rhash.rh_set(data, *
|
171
|
+
rhash.rh_set(data, *(rhash_kpath.tree))
|
173
172
|
end
|
174
173
|
|
175
174
|
entr = Lorj::SSLCrypt.new_encrypt_key
|
@@ -181,6 +180,22 @@ module Lorj
|
|
181
180
|
|
182
181
|
private
|
183
182
|
|
183
|
+
# Internal function to determine which section/key to set in export file
|
184
|
+
#
|
185
|
+
# It should support Array or String with syntax 'section#key'
|
186
|
+
def _export_keys_as_keypath(k, v)
|
187
|
+
rhash_kpath = KeyPath.new(Lorj.data.first_section(k))
|
188
|
+
if v.key?(:keys)
|
189
|
+
if v[:keys].is_a?(String)
|
190
|
+
section, key = Lorj.data.first_section(v[:keys])
|
191
|
+
rhash_kpath = KeyPath.new([section, key])
|
192
|
+
else
|
193
|
+
rhash_kpath = KeyPath.new(v[:keys])
|
194
|
+
end
|
195
|
+
end
|
196
|
+
rhash_kpath
|
197
|
+
end
|
198
|
+
|
184
199
|
def _export_processes(processes_options)
|
185
200
|
export_data = []
|
186
201
|
PrcLib.processes.each do |p|
|
data/lib/core/core_process.rb
CHANGED
@@ -44,7 +44,7 @@ module Lorj
|
|
44
44
|
# - Error if the create_e process handler raise an error.
|
45
45
|
#
|
46
46
|
def process_create(object_type, hConfig = nil)
|
47
|
-
return nil unless object_type
|
47
|
+
return nil unless object_type.is_a?(Symbol)
|
48
48
|
|
49
49
|
_add_instant_config(hConfig)
|
50
50
|
|
@@ -64,6 +64,7 @@ module Lorj
|
|
64
64
|
# This object is a meta object, without any data.
|
65
65
|
# Used to build other kind of objects.
|
66
66
|
object = Lorj::Data.new
|
67
|
+
object.base = self
|
67
68
|
object.set({}, object_type) {}
|
68
69
|
else
|
69
70
|
# build Function params to pass to the event handler.
|
@@ -116,7 +117,7 @@ module Lorj
|
|
116
117
|
# - Error if the query_e process handler raise an error.
|
117
118
|
#
|
118
119
|
def process_delete(object_type, hConfig = nil)
|
119
|
-
return nil unless object_type
|
120
|
+
return nil unless object_type.is_a?(Symbol)
|
120
121
|
|
121
122
|
_add_instant_config(hConfig)
|
122
123
|
|
@@ -200,7 +201,7 @@ module Lorj
|
|
200
201
|
#
|
201
202
|
#
|
202
203
|
def process_query(object_type, hQuery, hConfig = nil)
|
203
|
-
return nil unless object_type
|
204
|
+
return nil unless object_type.is_a?(Symbol)
|
204
205
|
|
205
206
|
_add_instant_config(hConfig)
|
206
207
|
|
@@ -291,7 +292,7 @@ module Lorj
|
|
291
292
|
# - Error if the get_e process handler raise an error.
|
292
293
|
#
|
293
294
|
def process_get(object_type, sUniqId, hConfig = nil)
|
294
|
-
return nil unless object_type
|
295
|
+
return nil unless object_type.is_a?(Symbol)
|
295
296
|
|
296
297
|
_add_instant_config(hConfig)
|
297
298
|
|
@@ -344,9 +345,9 @@ module Lorj
|
|
344
345
|
# updating.
|
345
346
|
#
|
346
347
|
# * *Returns* :
|
347
|
-
#
|
348
|
-
#
|
349
|
-
#
|
348
|
+
# - Lorj::Data of type :object
|
349
|
+
# OR
|
350
|
+
# - Lorj::Data empty.
|
350
351
|
#
|
351
352
|
# * *Raises* :
|
352
353
|
# - Warning if the Config data passed are not required by the meta object
|
@@ -357,7 +358,7 @@ module Lorj
|
|
357
358
|
# - Error if the get_e process handler raise an error.
|
358
359
|
#
|
359
360
|
def process_update(object_type, hConfig = nil)
|
360
|
-
return nil unless object_type
|
361
|
+
return nil unless object_type.is_a?(Symbol)
|
361
362
|
|
362
363
|
_add_instant_config(hConfig)
|
363
364
|
|
@@ -394,6 +395,83 @@ module Lorj
|
|
394
395
|
@object_data.add(object)
|
395
396
|
end
|
396
397
|
end
|
398
|
+
|
399
|
+
# Function to execute an object update. This function returns a Lorj::Data
|
400
|
+
# of type :object, refreshed.
|
401
|
+
#
|
402
|
+
# It uses the event 'refresh_e'. If not defined, the refresh is simply not
|
403
|
+
# executed. No warning exposed, but a debug info is thrown.
|
404
|
+
#
|
405
|
+
# refresh_e is defined and called as follow:
|
406
|
+
#
|
407
|
+
# BaseDefinition class derived function. This Process function should do any
|
408
|
+
# task required to execute a refresh of the object passed.
|
409
|
+
# The controller object data should be extracted by the controller_refresh
|
410
|
+
# call to refresh :attrs. See #controller_refresh.
|
411
|
+
# It should return true or false if the object refresh was done successfully
|
412
|
+
# or not
|
413
|
+
#
|
414
|
+
# It is possible to call directly the controller_refresh as the process
|
415
|
+
# event
|
416
|
+
#
|
417
|
+
# * *args*:
|
418
|
+
# - object_type: The object_type to refresh
|
419
|
+
# - object : The Lorj::Data object to refresh
|
420
|
+
#
|
421
|
+
# * *returns*:
|
422
|
+
# - boolean : true if refresh was executed successfully.
|
423
|
+
# false otherwise.
|
424
|
+
#
|
425
|
+
# From the object itself, you can call object.refresh. This will call this
|
426
|
+
# function.
|
427
|
+
#
|
428
|
+
# The controller event usually called is controller_refresh.
|
429
|
+
#
|
430
|
+
# * *Args* :
|
431
|
+
# - +object_type+ : Meta object type to query.
|
432
|
+
# - +config+ : Optional. Hash containing list of data to use for
|
433
|
+
# updating.
|
434
|
+
#
|
435
|
+
# * *Returns* :
|
436
|
+
# - boolean : true if the refresh was executed successfully.
|
437
|
+
# false otherwise.
|
438
|
+
#
|
439
|
+
# * *Raises* :
|
440
|
+
# - Warning if the Config data passed are not required by the meta object
|
441
|
+
# (or dependencies) at creation time.
|
442
|
+
# - Error if ObjectType has never been declared.
|
443
|
+
# - Error if the dependencies get_e process handler did not return any
|
444
|
+
# data. (nil) - Loop detection.
|
445
|
+
# - Error if the get_e process handler raise an error.
|
446
|
+
#
|
447
|
+
def process_refresh(object)
|
448
|
+
return nil unless object.is_a?(Lorj::Data) && object.type == :object &&
|
449
|
+
!object.empty?
|
450
|
+
|
451
|
+
object_type = object.object_type?
|
452
|
+
|
453
|
+
unless PrcLib.model.meta_obj.rh_exist?(object_type)
|
454
|
+
PrcLib.runtime_fail "$s.%s: '%s' is not a known object type.",
|
455
|
+
self.class, __callee__, object_type
|
456
|
+
end
|
457
|
+
|
458
|
+
proc = PrcLib.model.meta_obj.rh_get(object_type, :lambdas, :refresh_e)
|
459
|
+
|
460
|
+
if proc.nil?
|
461
|
+
Lorj.debug(1, "No 'refresh_e' event found for object type '%s'",
|
462
|
+
object_type)
|
463
|
+
return false
|
464
|
+
end
|
465
|
+
|
466
|
+
ret = @process.method(proc).call(object_type, object)
|
467
|
+
|
468
|
+
unless ret.boolean?
|
469
|
+
Lorj.debug(1, "'%s' has not returned a boolean. Consider return false.",
|
470
|
+
object_type)
|
471
|
+
ret = false
|
472
|
+
end
|
473
|
+
ret
|
474
|
+
end
|
397
475
|
end
|
398
476
|
|
399
477
|
# Adding private process core functions.
|
data/lib/core/definition.rb
CHANGED
@@ -125,6 +125,7 @@ module Lorj
|
|
125
125
|
# - :get_e : Process function to call with get
|
126
126
|
# - :query_e : Process function to call with query
|
127
127
|
# - :get_attr_e : Process function to call with get_attr
|
128
|
+
# - :refresh_e : Process function to call with refresh
|
128
129
|
def self.define_obj(obj_type_name, handlers = nil)
|
129
130
|
return nil unless [NilClass, String, Symbol].include?(obj_type_name.class)
|
130
131
|
PrcLib.model.heap true
|
@@ -634,7 +635,8 @@ module Lorj
|
|
634
635
|
# TODO: Cleanup un-used 2 levels :params/:keys by single :params
|
635
636
|
object = { :lambdas => { :create_e => nil, :delete_e => nil,
|
636
637
|
:update_e => nil, :get_e => nil,
|
637
|
-
:query_e => nil, :get_attr_e => nil
|
638
|
+
:query_e => nil, :get_attr_e => nil,
|
639
|
+
:refresh_e => nil },
|
638
640
|
:params => { :keys => {} },
|
639
641
|
:options => { :controller => use_controller },
|
640
642
|
:query_mapping => { ':id' => ':id', ':name' => ':name' },
|
@@ -64,6 +64,27 @@ module Lorj
|
|
64
64
|
controller_error 'update_object has not been redefined by the controller.'
|
65
65
|
end
|
66
66
|
|
67
|
+
# controller refresh handlers which needs to be defined by the controller,
|
68
|
+
# this function should execute a controller data refresh
|
69
|
+
#
|
70
|
+
# The controller must respect the following rule:
|
71
|
+
# - If the refresh was unsuccessful, due to errors, the original object
|
72
|
+
# should be kept intact.
|
73
|
+
# - A boolean should be return to inform that therefresh was executed
|
74
|
+
# successfully or not.
|
75
|
+
#
|
76
|
+
# * *parameters:*
|
77
|
+
# - +object_type+: Lorj object type to use for the refresh.
|
78
|
+
# - +object+ : object to refresh.
|
79
|
+
#
|
80
|
+
# * *returns*:
|
81
|
+
# - boolean: true if refresh was executed successfully.
|
82
|
+
# false otherwise.
|
83
|
+
#
|
84
|
+
def refresh(_sObjectType, _oObject)
|
85
|
+
controller_error 'refresh_object has not been redefined by the controller'
|
86
|
+
end
|
87
|
+
|
67
88
|
# Simply raise an error
|
68
89
|
#
|
69
90
|
# * *Args* :
|
@@ -153,6 +153,7 @@ module Lorj
|
|
153
153
|
'as Lorj::Data object if ObjectType is not given.',
|
154
154
|
oObject.class unless sObjectType
|
155
155
|
data_objects = Lorj::Data.new(sDataType)
|
156
|
+
data_objects.base = self
|
156
157
|
data_objects.set(oObject, sObjectType) do |sObjType, oControlerObject|
|
157
158
|
_return_map(sObjType, oControlerObject)
|
158
159
|
end
|
@@ -75,6 +75,11 @@ module Lorj
|
|
75
75
|
params = nil unless params.is_a?(Hash)
|
76
76
|
@base_object.controller_get(sObjectType, sId, params)
|
77
77
|
end
|
78
|
+
|
79
|
+
def controller_refresh(sObjectType, object) #:doc:
|
80
|
+
process_error 'No Controler object loaded.' unless @base_object
|
81
|
+
@base_object.controller_refresh(sObjectType, object)
|
82
|
+
end
|
78
83
|
end
|
79
84
|
|
80
85
|
# class describing generic Object Process
|
@@ -104,6 +109,11 @@ module Lorj
|
|
104
109
|
process_error 'No Base object loaded.' unless @base_object
|
105
110
|
@base_object.process_delete(sObjectType, hConfig)
|
106
111
|
end
|
112
|
+
|
113
|
+
def process_refresh(sObjectType, object) #:doc:
|
114
|
+
process_error 'No Base object loaded.' unless @base_object
|
115
|
+
@base_object.process_refresh(sObjectType, object)
|
116
|
+
end
|
107
117
|
end
|
108
118
|
|
109
119
|
# class describing generic Object Process
|
data/lib/core/lorj_data.rb
CHANGED
@@ -89,6 +89,31 @@ module Lorj
|
|
89
89
|
# Return Lorj::Data object type
|
90
90
|
attr_reader :type
|
91
91
|
|
92
|
+
def base=(base)
|
93
|
+
@base = base if @base.nil? && base.is_a?(Lorj::BaseDefinition)
|
94
|
+
@base
|
95
|
+
end
|
96
|
+
|
97
|
+
# Do an object refresh by calling the process_refresh function if
|
98
|
+
# the process has been provided.
|
99
|
+
#
|
100
|
+
# For details on refresh call, see #BaseDefinition.process_refresh
|
101
|
+
#
|
102
|
+
# * *Args* :
|
103
|
+
# Nothing
|
104
|
+
#
|
105
|
+
# * *Returns* :
|
106
|
+
# - +status+ : Boolean.
|
107
|
+
# true if refresh is successful
|
108
|
+
# false otherwise
|
109
|
+
def refresh
|
110
|
+
return false if empty? || @base.nil?
|
111
|
+
return false unless @base.is_a?(Lorj::BaseDefinition) &&
|
112
|
+
@base.class.method_defined?(:process_refresh)
|
113
|
+
|
114
|
+
@base.process_refresh(self)
|
115
|
+
end
|
116
|
+
|
92
117
|
# Return :object type of the Lorj::Data object.
|
93
118
|
#
|
94
119
|
# * *Args* :
|
@@ -112,21 +137,20 @@ module Lorj
|
|
112
137
|
# - Set from a Lorj::Data.
|
113
138
|
# ex: if data is already a Lorj::Data,
|
114
139
|
# copy = Lorj::Data.new()
|
140
|
+
# copy.base = self
|
115
141
|
# copy.set(data)
|
116
142
|
# - Set from an object, not Lorj::Data and not a list.
|
117
143
|
# ex:
|
118
144
|
# data = { :test => 'toto'}
|
119
145
|
# copy = Lorj::Data.new()
|
120
|
-
# copy.
|
121
|
-
#
|
122
|
-
# }
|
146
|
+
# copy.base = self
|
147
|
+
# copy.set(data, :object) { |oObject | oObject }
|
123
148
|
# - Set from a list of objects, not Lorj::Data and not a :object.
|
124
149
|
# ex:
|
125
150
|
# data = [{ :name => 'toto'}, {:name => 'test'}]
|
126
151
|
# copy = Lorj::Data.new()
|
127
|
-
# copy.
|
128
|
-
#
|
129
|
-
# }
|
152
|
+
# copy.base = self
|
153
|
+
# copy.set(data, :list, { :name => /^t/ }) { |oObject | oObject }
|
130
154
|
#
|
131
155
|
# * *Args* :
|
132
156
|
# - +data+ : Lorj::Data or any other data.
|
@@ -149,6 +173,8 @@ module Lorj
|
|
149
173
|
def set(oObj, sObjType = nil, hQuery = {})
|
150
174
|
return obj_data_set(oObj, sObjType) if oObj.is_a?(Lorj::Data)
|
151
175
|
|
176
|
+
return nil unless block_given?
|
177
|
+
|
152
178
|
# while saving the object, a mapping work is done?
|
153
179
|
case @type
|
154
180
|
when :data, :object
|
@@ -222,6 +248,7 @@ module Lorj
|
|
222
248
|
# ex:
|
223
249
|
# data = { :name => 'toto'}
|
224
250
|
# copy = Lorj::Data.new()
|
251
|
+
# copy.base = self
|
225
252
|
# copy.set(data, :object) { |oObject |
|
226
253
|
# {:real_name => oObject[:name]}
|
227
254
|
# }
|
@@ -239,6 +266,7 @@ module Lorj
|
|
239
266
|
# ex:
|
240
267
|
# data = [{ :name => 'toto'}, {:name => 'test'}]
|
241
268
|
# copy = Lorj::Data.new()
|
269
|
+
# copy.base = self
|
242
270
|
# copy.set(data, :list, { :name => /^t/ }) { |oObject |
|
243
271
|
# {:real_name => oObject[:name]}
|
244
272
|
# }
|
@@ -309,6 +337,7 @@ module Lorj
|
|
309
337
|
# {:real_name => oObject[:name]}
|
310
338
|
# }
|
311
339
|
# list = Lorj::Data.new()
|
340
|
+
# list.base = self
|
312
341
|
#
|
313
342
|
# puts data.exist?(:object) # => false
|
314
343
|
#
|
data/lib/lorj/version.rb
CHANGED
@@ -71,6 +71,7 @@ describe 'Lorj::ObjectData' do
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
74
|
+
|
74
75
|
context 'initialize with internal true' do
|
75
76
|
before(:all) do
|
76
77
|
@obj_data = Lorj::ObjectData.new(true)
|
@@ -78,10 +79,12 @@ describe 'Lorj::ObjectData' do
|
|
78
79
|
data = [{ :name => 'toto' }]
|
79
80
|
@internal_data.set(data, :list, :name => /^t/) { |oObject| oObject }
|
80
81
|
end
|
82
|
+
|
81
83
|
it 'Test method #add' do
|
82
84
|
@obj_data.add(@internal_data)
|
83
85
|
expect(@obj_data.exist?(:list)).to eq(true)
|
84
86
|
end
|
87
|
+
|
85
88
|
it 'Test method #delete' do
|
86
89
|
deleted_data = @obj_data.delete(@internal_data)
|
87
90
|
expect(@obj_data.exist?(:list)).to eq(false)
|
@@ -0,0 +1,99 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
|
18
|
+
# To debug spec, depending on Ruby version, you may need to install
|
19
|
+
# 1.8 => ruby-debug
|
20
|
+
# 1.9 => debugger
|
21
|
+
# 2.0+ => byebug
|
22
|
+
# The right debugger should be installed by default by bundle
|
23
|
+
# So, just call:
|
24
|
+
#
|
25
|
+
# bundle
|
26
|
+
#
|
27
|
+
# Then set RSPEC_DEBUG=true, put a 'stop' where you want in the spec code
|
28
|
+
# and start rspec or even rake spec.
|
29
|
+
#
|
30
|
+
# RSPEC_DEBUG=true rake spec_local (or spec which includes docker spec)
|
31
|
+
# OR
|
32
|
+
# RSPEC_DEBUG=true rspec -f doc --color spec/<file>_spec.rb
|
33
|
+
#
|
34
|
+
|
35
|
+
app_path = File.dirname(__FILE__)
|
36
|
+
$LOAD_PATH << app_path unless $LOAD_PATH.include?(app_path)
|
37
|
+
require 'spec_helper'
|
38
|
+
|
39
|
+
describe 'Lorj::Data' do
|
40
|
+
context 'initialize' do
|
41
|
+
it 'data.type? == :object by default' do
|
42
|
+
expect(Lorj::Data.new).to be
|
43
|
+
data = Lorj::Data.new
|
44
|
+
expect(data.type).to equal(:object)
|
45
|
+
expect(data.object_type?).to equal(nil)
|
46
|
+
expect(data.empty?).to equal(true)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'data.type? == :list if requested' do
|
50
|
+
expect(Lorj::Data.new :list).to be
|
51
|
+
data = Lorj::Data.new :list
|
52
|
+
expect(data.type).to equal(:list)
|
53
|
+
expect(data.object_type?).to equal(nil)
|
54
|
+
expect(data.empty?).to equal(true)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'as :object' do
|
59
|
+
before(:all) do
|
60
|
+
# Spec testing for process refresh
|
61
|
+
class SpecObject < Lorj::BaseDefinition
|
62
|
+
def initialize
|
63
|
+
end
|
64
|
+
|
65
|
+
def process_refresh(*_p)
|
66
|
+
true
|
67
|
+
end
|
68
|
+
end
|
69
|
+
@spec_object = SpecObject.new
|
70
|
+
@data = Lorj::Data.new
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'data.object_type?'
|
74
|
+
it 'data.set(...)'
|
75
|
+
it 'data.exist?'
|
76
|
+
it 'data.empty?'
|
77
|
+
it 'data.type'
|
78
|
+
it 'data.type = '
|
79
|
+
it 'data.get'
|
80
|
+
it 'data[...]'
|
81
|
+
it 'data.length'
|
82
|
+
it 'data.each'
|
83
|
+
it 'data.each_index'
|
84
|
+
it 'data.to_a'
|
85
|
+
it 'data.is_registered'
|
86
|
+
it 'data.register'
|
87
|
+
it 'data.unregister'
|
88
|
+
|
89
|
+
it 'data.base = BaseDefinition instance should expose process_refresh' do
|
90
|
+
expect(@data.refresh).to equal(false)
|
91
|
+
expect(@data.base = @spec_object).to equal(@spec_object)
|
92
|
+
expect(@data.refresh).to equal(false)
|
93
|
+
data = { :test => 'toto' }
|
94
|
+
@data.set(data, :test) { |_t, o| o }
|
95
|
+
# It requires data and process to refresh itself.
|
96
|
+
expect(@data.refresh).to equal(true)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -165,7 +165,7 @@ describe 'Internal BaseDefinition features' do
|
|
165
165
|
end
|
166
166
|
|
167
167
|
it 'account_export({"credentials#key" => {:keys => [:server, :key]}})'\
|
168
|
-
' returns ' do
|
168
|
+
' returns data with :server/:key instead of :credentials/:key' do
|
169
169
|
map = { 'credentials#key' => { :keys => [:server, :key] } }
|
170
170
|
entr, export_dat = @spec_obj.account_export(map)
|
171
171
|
export_dat = YAML.load(export_dat)
|
@@ -177,6 +177,19 @@ describe 'Internal BaseDefinition features' do
|
|
177
177
|
expect(data.rh_exist?(:account, :name)).to equal(true)
|
178
178
|
end
|
179
179
|
|
180
|
+
it "account_export({'credentials#key' => {:keys => 'server#key'}})"\
|
181
|
+
' returns data with :server/:key instead of :credentials/:key' do
|
182
|
+
map = { 'credentials#key' => { :keys => 'server#key' } }
|
183
|
+
entr, export_dat = @spec_obj.account_export(map)
|
184
|
+
export_dat = YAML.load(export_dat)
|
185
|
+
dat_decrypted = Lorj::SSLCrypt.get_encrypted_value(export_dat[:enc_data],
|
186
|
+
entr, 'data encrypted')
|
187
|
+
data = YAML.load(dat_decrypted)
|
188
|
+
expect(data.rh_exist?(:credentials, :key)).to equal(false)
|
189
|
+
expect(data.rh_exist?(:server, :key)).to equal(true)
|
190
|
+
expect(data.rh_exist?(:account, :name)).to equal(true)
|
191
|
+
end
|
192
|
+
|
180
193
|
it 'account_data_import(data) update the "account layer"' do
|
181
194
|
entr, export_dat = @spec_obj.account_export
|
182
195
|
export_dat = YAML.load(export_dat)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lorj
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- forj team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -276,6 +276,7 @@ files:
|
|
276
276
|
- lorj.gemspec
|
277
277
|
- spec/05_lorj_keypath_spec.rb
|
278
278
|
- spec/06_lorj_object_data_spec.rb
|
279
|
+
- spec/07_lorj_data_spec.rb
|
279
280
|
- spec/09_prc_spec.rb
|
280
281
|
- spec/10_lorj_log_spec.rb
|
281
282
|
- spec/11_lorj_defaults_spec.rb
|
@@ -317,6 +318,7 @@ summary: Process Controllers framework system
|
|
317
318
|
test_files:
|
318
319
|
- spec/05_lorj_keypath_spec.rb
|
319
320
|
- spec/06_lorj_object_data_spec.rb
|
321
|
+
- spec/07_lorj_data_spec.rb
|
320
322
|
- spec/09_prc_spec.rb
|
321
323
|
- spec/10_lorj_log_spec.rb
|
322
324
|
- spec/11_lorj_defaults_spec.rb
|