lorj 1.0.10 → 1.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +8 -2
- data/lib/core/core.rb +25 -15
- data/lib/core/core_internal.rb +82 -6
- data/lib/core/core_object_params.rb +43 -12
- data/lib/core/core_process_setup.rb +60 -172
- data/lib/core/core_setup_ask.rb +18 -3
- data/lib/core/core_setup_init.rb +929 -58
- data/lib/core/core_setup_list.rb +6 -3
- data/lib/core/definition.rb +2 -2
- data/lib/core/definition_internal.rb +1 -1
- data/lib/core/lorj_basedefinition.rb +6 -0
- data/lib/core/process.rb +67 -8
- data/lib/logging.rb +9 -5
- data/lib/lorj/version.rb +2 -2
- data/lib/lorj_account.rb +40 -20
- data/lib/lorj_config.rb +7 -2
- data/lib/lorj_defaults.rb +7 -4
- data/lib/lorj_meta.rb +61 -16
- data/lorj-spec/{controllers → process/mock/controllers}/mock/mock.rb +0 -0
- data/lorj-spec/{data.yaml → process/mock/data.yaml} +0 -0
- data/lorj-spec/process/mock/defaults.yaml +42 -0
- data/lorj-spec/{providers → process/mock/providers}/mock2/mock2.rb +0 -0
- data/lorj-spec/process/mock_process.rb +1 -1
- data/lorj-spec/providers_extra/mock3/mock3.rb +144 -0
- data/lorj.gemspec +1 -1
- data/spec/05_lorj_keypath_spec.rb +128 -2
- data/spec/06_lorj_object_data_spec.rb +77 -0
- data/spec/13_lorj_account_spec.rb +67 -0
- data/spec/20_lorj_meta_spec.rb +17 -7
- data/spec/21_lorj_processes_spec.rb +54 -23
- data/spec/22_lorj_core_spec.rb +49 -0
- metadata +13 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4650a17061896bba5bafad8e12d15be96a37a532
|
4
|
+
data.tar.gz: 9ed6bb8936335cc1fa1c1236e95ef1c17a56e7e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9842cbc6ccf9d6068a76a0b82948a1c6196e10f5d46d9a40d12166961d2a328e5514a95e761387ef6a634783e851386cfcd0f48de4c4c4eba35c1d6bf9c56f1
|
7
|
+
data.tar.gz: f499cab40cd49a2494ff67e59a38704e4a193acff174b1df7dacf547f9ba13bce7c6796e344c63f00f01c043f4d54a70a9da51ec0326cb90c96686187b7a5adc
|
data/.rubocop.yml
CHANGED
@@ -33,14 +33,20 @@ Style/HashSyntax:
|
|
33
33
|
|
34
34
|
# lets start with 40, but 10 is way to small..
|
35
35
|
Metrics/MethodLength:
|
36
|
-
Max:
|
36
|
+
Max: 50
|
37
37
|
# If Method length is increased, class length need to be extended as well.
|
38
38
|
Metrics/ClassLength:
|
39
39
|
Max: 150
|
40
40
|
|
41
41
|
# allow arguments to be longer than 15
|
42
42
|
Metrics/AbcSize:
|
43
|
-
Max:
|
43
|
+
Max: 50
|
44
|
+
# Perceived Complexity
|
45
|
+
Metrics/PerceivedComplexity:
|
46
|
+
Max: 9
|
47
|
+
Metrics/CyclomaticComplexity:
|
48
|
+
Max: 8
|
49
|
+
|
44
50
|
# forj-docker binary name gets an exception
|
45
51
|
Style/FileName:
|
46
52
|
Exclude: ['bin/forj-docker', 'lib/**/forj-docker.rb']
|
data/lib/core/core.rb
CHANGED
@@ -30,7 +30,7 @@ module Lorj
|
|
30
30
|
# This is the main lorj class.
|
31
31
|
# It interfaces your main code with the full lorj system as shown in the
|
32
32
|
# concept document.
|
33
|
-
# It
|
33
|
+
# It gives you access to the lorj model object designed by your process.
|
34
34
|
#
|
35
35
|
# When you start using it, your main must be as simple as you can, as you will
|
36
36
|
# need to move most of your application logic to the process.
|
@@ -46,19 +46,29 @@ module Lorj
|
|
46
46
|
# Then, your application contributors can build their own controller and
|
47
47
|
# extend your solution!
|
48
48
|
#
|
49
|
-
# Here an example of creating a CloudServer, using
|
50
|
-
#
|
51
|
-
# CloudCore introduces lorj predefined CloudProcess used by forj cli.
|
49
|
+
# Here an example of creating a CloudServer, using Lorj_cloud module
|
50
|
+
# See http://github.com/forj-oss/lorj-cloud
|
52
51
|
#
|
53
|
-
#
|
54
|
-
# oConfig.set(:server_name,'myservername')
|
55
|
-
# oCloud.create(:server)
|
52
|
+
# require 'lorj_cloud'
|
56
53
|
#
|
57
|
-
#
|
54
|
+
# process = { :process_module => 'cloud',
|
55
|
+
# :controller_name => 'openstack' }
|
56
|
+
# cloud = Lorj::Core.new(nil, [process])
|
57
|
+
# cloud.setup(:server) # Ask end user about required data
|
58
|
+
# cloud.create(:server, :server_name => 'myservername')
|
58
59
|
#
|
59
|
-
#
|
60
|
-
#
|
61
|
-
#
|
60
|
+
# Another basic example.
|
61
|
+
#
|
62
|
+
# require 'lorj'
|
63
|
+
#
|
64
|
+
# process = { :process_name => 'myprocess',
|
65
|
+
# :process_path => '<myprocess_path>',
|
66
|
+
# :controller_name => :mock }
|
67
|
+
#
|
68
|
+
# core = Lorj::Core.new(nil, [process])
|
69
|
+
# core.create(:myobject, :parameter1 => "value")
|
70
|
+
#
|
71
|
+
# You can learn on lorj by example, see examples/
|
62
72
|
#
|
63
73
|
# See BaseProcess to check how you can write a process and what kind of
|
64
74
|
# functions are available for your process to be kept controller independant.
|
@@ -71,8 +81,8 @@ module Lorj
|
|
71
81
|
# following functions:
|
72
82
|
#
|
73
83
|
# - get(*key, default=nil) and [*key] : function to get a value from a key.
|
74
|
-
#
|
75
|
-
#
|
84
|
+
# default is a value to get if not found.
|
85
|
+
#
|
76
86
|
# - set(*key, value) or [*key, value]= : function to set a value to a key.
|
77
87
|
# Ex: From processes, you can set a runtime data with:
|
78
88
|
#
|
@@ -83,9 +93,9 @@ module Lorj
|
|
83
93
|
# config[key] = value
|
84
94
|
#
|
85
95
|
# - exist?(*key) : function which return false if not
|
86
|
-
#
|
96
|
+
# found, or any other value if found.
|
87
97
|
# Ex: From processes, you can get a data (runtime/account/config.yaml or
|
88
|
-
#
|
98
|
+
# defaults.yaml) with:
|
89
99
|
#
|
90
100
|
# config.get(key)
|
91
101
|
#
|
data/lib/core/core_internal.rb
CHANGED
@@ -222,6 +222,8 @@ module Lorj
|
|
222
222
|
# This path must contains at least 'process' subdir. And if needed
|
223
223
|
# a 'controllers' path
|
224
224
|
# - :process_name : Name of the local process
|
225
|
+
# - :defaults : Define the defaults data setting for the process
|
226
|
+
# - :data : Define process data definition.
|
225
227
|
#
|
226
228
|
# Optionnally, you can set a controller name to use with the process.
|
227
229
|
# - :controller_name: Name of the controller to use.
|
@@ -230,13 +232,13 @@ module Lorj
|
|
230
232
|
# * *Returns* :
|
231
233
|
# - model : Application model loaded.
|
232
234
|
def init_processes(model, processes)
|
233
|
-
processes.
|
235
|
+
processes.each_index do |index|
|
234
236
|
my_process = {}
|
235
|
-
|
237
|
+
a_process = processes[index]
|
236
238
|
if a_process.key?(:process_module)
|
237
|
-
my_process = _process_module_to_load(my_process, a_process)
|
239
|
+
my_process = _process_module_to_load(index, my_process, a_process)
|
238
240
|
else
|
239
|
-
my_process = _process_local_to_load(my_process, a_process)
|
241
|
+
my_process = _process_local_to_load(index, my_process, a_process)
|
240
242
|
end
|
241
243
|
|
242
244
|
next if my_process.nil?
|
@@ -248,7 +250,10 @@ module Lorj
|
|
248
250
|
|
249
251
|
model
|
250
252
|
end
|
253
|
+
end
|
251
254
|
|
255
|
+
# Define internal private functions for controllers
|
256
|
+
class Core
|
252
257
|
# high level function to load process
|
253
258
|
def _process_load(model, my_process)
|
254
259
|
if load_process(model, my_process[:process_path])
|
@@ -263,7 +268,7 @@ module Lorj
|
|
263
268
|
end
|
264
269
|
|
265
270
|
# function prepare of loading a local process
|
266
|
-
def _process_local_to_load(my_process, a_process)
|
271
|
+
def _process_local_to_load(index, my_process, a_process)
|
267
272
|
my_process[:process_path] = a_process[:process_path]
|
268
273
|
|
269
274
|
if a_process[:process_name].nil?
|
@@ -277,11 +282,37 @@ module Lorj
|
|
277
282
|
else
|
278
283
|
my_process[:controller_name] = a_process[:controller_name]
|
279
284
|
end
|
285
|
+
|
286
|
+
defaults_file = a_process[:defaults]
|
287
|
+
if defaults_file.nil?
|
288
|
+
path = a_process[:process_path]
|
289
|
+
path['.rb'] = ''
|
290
|
+
defaults_file = File.join(path, 'defaults.yaml')
|
291
|
+
end
|
292
|
+
|
293
|
+
_process_load_data(config, index,
|
294
|
+
a_process[:process_name], defaults_file,
|
295
|
+
PRC::SectionConfig)
|
296
|
+
|
297
|
+
data_file = a_process[:data]
|
298
|
+
if defaults_file.nil?
|
299
|
+
path = a_process[:process_path]
|
300
|
+
path['.rb'] = ''
|
301
|
+
data_file = File.join(path, 'data.yaml')
|
302
|
+
end
|
303
|
+
|
304
|
+
_process_load_data(Lorj.data, index,
|
305
|
+
a_process[:process_name], data_file)
|
306
|
+
|
307
|
+
# TODO: Implement Object definition as a config layer.
|
308
|
+
# _process_load_definition(definition, index, a_process[:process_name],
|
309
|
+
# a_process[:definition])
|
310
|
+
|
280
311
|
my_process
|
281
312
|
end
|
282
313
|
|
283
314
|
# Function prepare of loading a module process.
|
284
|
-
def _process_module_to_load(my_process, a_process)
|
315
|
+
def _process_module_to_load(index, my_process, a_process)
|
285
316
|
name = a_process[:process_module]
|
286
317
|
|
287
318
|
if name.nil?
|
@@ -309,9 +340,54 @@ module Lorj
|
|
309
340
|
_process_module_set_ctr(my_process, module_process.controllers,
|
310
341
|
a_process[:controller_name])
|
311
342
|
|
343
|
+
_process_load_data(config, index, name, module_process.defaults_file,
|
344
|
+
PRC::SectionConfig)
|
345
|
+
|
346
|
+
_process_load_data(Lorj.data, index, name, module_process.data_file)
|
347
|
+
|
348
|
+
# TODO: Implement Object definition as a config layer.
|
349
|
+
# _process_load_definition(definition, index, name,
|
350
|
+
# module_process.definition)
|
351
|
+
|
312
352
|
my_process
|
313
353
|
end
|
314
354
|
|
355
|
+
# Load data definition in process data layers
|
356
|
+
def _process_load_data(config, index, name, file,
|
357
|
+
config_class = PRC::BaseConfig)
|
358
|
+
return unless config.layer_index(name).nil?
|
359
|
+
|
360
|
+
return if file.nil?
|
361
|
+
|
362
|
+
layer = PRC::CoreConfig.define_layer(:name => name,
|
363
|
+
:config => config_class.new,
|
364
|
+
:load => true,
|
365
|
+
:set => false)
|
366
|
+
unless File.exist?(file)
|
367
|
+
PrcLib.warning("Process '%s', data file '%s' doesn't exist."\
|
368
|
+
' Not loaded.', name, file)
|
369
|
+
return
|
370
|
+
end
|
371
|
+
|
372
|
+
begin
|
373
|
+
unless layer[:config].load(file)
|
374
|
+
PrcLib.warning("Process '%s', data file '%s' was not loaded.",
|
375
|
+
name, file)
|
376
|
+
end
|
377
|
+
rescue => e
|
378
|
+
PrcLib.error("Process '%s', unable to load data file '%s'. %s",
|
379
|
+
name, file, e.message)
|
380
|
+
end
|
381
|
+
|
382
|
+
config.layer_add(layer.merge(:index => (config.layers.length - index)))
|
383
|
+
end
|
384
|
+
|
385
|
+
# Load process definition in process layers
|
386
|
+
# Function currently not developped.
|
387
|
+
#
|
388
|
+
# def _process_load_definition(a_process)
|
389
|
+
# end
|
390
|
+
|
315
391
|
def _process_module_set_ctr(my_process, controllers, controller_name)
|
316
392
|
return if controller_name.nil?
|
317
393
|
|
@@ -205,10 +205,6 @@ module Lorj
|
|
205
205
|
_get_object_params(object_type, sEventType, fname, true)
|
206
206
|
end
|
207
207
|
|
208
|
-
# TODO: Fix the Complexity
|
209
|
-
# rubocop: disable Metrics/CyclomaticComplexity
|
210
|
-
# rubocop: disable Metrics/PerceivedComplexity
|
211
|
-
|
212
208
|
# internal runtime function for process call
|
213
209
|
# Build a process/controller parameters object (ObjectData)
|
214
210
|
#
|
@@ -241,12 +237,8 @@ module Lorj
|
|
241
237
|
new_params = _obj_param_init(object_type, sEventType, as_controller)
|
242
238
|
end
|
243
239
|
|
244
|
-
|
245
|
-
|
246
|
-
next unless param_options[:for].include?(sEventType)
|
247
|
-
end
|
248
|
-
|
249
|
-
param_obj = KeyPath.new(param_path)
|
240
|
+
_object_params_event(object_type, sEventType).each do |param_obj|
|
241
|
+
param_options = obj_params[param_obj.fpath]
|
250
242
|
|
251
243
|
value = _build_param(new_params, param_obj, param_options)
|
252
244
|
|
@@ -260,8 +252,47 @@ module Lorj
|
|
260
252
|
new_params
|
261
253
|
end
|
262
254
|
|
263
|
-
#
|
264
|
-
#
|
255
|
+
# Function to provide a list of valid attributes for an event given.
|
256
|
+
#
|
257
|
+
# * *args* :
|
258
|
+
# - +object_type+: object_type
|
259
|
+
# - +event_type+ : Can be create_e, delete_e, query_e, get_e
|
260
|
+
# - +param_type+ : Can be nil (default), :data or :CloudObject
|
261
|
+
#
|
262
|
+
# * *return*:
|
263
|
+
# - params_obj : List of valid attributes (KeyPath type) for
|
264
|
+
# the event given.
|
265
|
+
def _object_params_event(object_type, sEventType, param_type = nil)
|
266
|
+
obj_params = PrcLib.model.meta_obj.rh_get(object_type, :params, :keys)
|
267
|
+
|
268
|
+
attrs = []
|
269
|
+
obj_params.each do |param_path, param_options|
|
270
|
+
next unless _param_event?(param_options, sEventType)
|
271
|
+
|
272
|
+
next if param_type && param_type != param_options[:type]
|
273
|
+
|
274
|
+
attrs << KeyPath.new(param_path)
|
275
|
+
end
|
276
|
+
attrs
|
277
|
+
end
|
278
|
+
|
279
|
+
# Internal runtime function checking if the attribute is valid with event
|
280
|
+
# query
|
281
|
+
#
|
282
|
+
# * *args* :
|
283
|
+
# - +param_options+: Parameter options to use.
|
284
|
+
# - +param_path+ : Parameter path to check event
|
285
|
+
# - +event_type+ : Can be create_e, delete_e, query_e, get_e
|
286
|
+
#
|
287
|
+
# * *return*:
|
288
|
+
# - true if the attribute name is valid for this event.
|
289
|
+
# - false otherwise.
|
290
|
+
def _param_event?(param_options, sEventType)
|
291
|
+
if param_options.key?(:for)
|
292
|
+
return false unless param_options[:for].include?(sEventType)
|
293
|
+
end
|
294
|
+
true
|
295
|
+
end
|
265
296
|
|
266
297
|
# Internal runtime function for process call
|
267
298
|
#
|
@@ -129,12 +129,10 @@ module Lorj
|
|
129
129
|
PrcLib.runtime_fail "Setup: '%s' not a valid object type."
|
130
130
|
end
|
131
131
|
|
132
|
-
setup_steps = _setup_load
|
133
|
-
|
134
132
|
Lorj.debug(2, "Setup is identifying account data to ask for '%s'",
|
135
133
|
sObjectType)
|
136
134
|
# Loop in dependencies to get list of data object to setup
|
137
|
-
_setup_identify(sObjectType,
|
135
|
+
setup_steps = _setup_identify(sObjectType, _setup_load)
|
138
136
|
|
139
137
|
Lorj.debug(2, 'Setup check if needs to add unrelated data in the process')
|
140
138
|
_setup_check_additional(setup_steps)
|
@@ -152,39 +150,29 @@ module Lorj
|
|
152
150
|
# Internal function to insert the data after several data to ask.
|
153
151
|
#
|
154
152
|
# * *Args* :
|
155
|
-
# -
|
153
|
+
# - step : step structure to update.
|
156
154
|
# - data_to_add : data to add
|
157
|
-
# - step : current step analyzed.
|
158
155
|
# - order_index : last order index of the current step analyzed.
|
159
156
|
#
|
160
157
|
# * *Returns*:
|
161
158
|
#
|
162
159
|
# * *Raises* :
|
163
160
|
#
|
164
|
-
def _setup_data_insert(
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
next if order_to_check.nil?
|
176
|
-
|
177
|
-
step = iStepToCheck if iStepToCheck > step
|
178
|
-
level_index = iLevelToCheck if iLevelToCheck > level_index
|
179
|
-
order_index = order_to_check + 1 if order_to_check + 1 > order_index
|
180
|
-
break
|
181
|
-
end
|
182
|
-
end
|
161
|
+
def _setup_data_insert(step, data_to_add)
|
162
|
+
order_index = _setup_data_where?(step[:order], data_to_add)
|
163
|
+
|
164
|
+
if order_index.nil?
|
165
|
+
level_index = step[:order].keys.max
|
166
|
+
step[:order][level_index] << data_to_add
|
167
|
+
Lorj.debug(3, "%s/L%s/O%s: '%s' added in setup list at position.",
|
168
|
+
step[:name], level_index,
|
169
|
+
step[:order][level_index].length - 1,
|
170
|
+
data_to_add)
|
171
|
+
return
|
183
172
|
end
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
step, level_index, order_index, data_to_add)
|
173
|
+
step[:order][order_index[0]].insert(order_index[1], data_to_add)
|
174
|
+
Lorj.debug(3, "%s/L%s/O%s: '%s' added in setup list at position.",
|
175
|
+
step[:name], order_index[0], order_index[1], data_to_add)
|
188
176
|
end
|
189
177
|
|
190
178
|
# Internal function to get :after list of data to ask.
|
@@ -198,13 +186,51 @@ module Lorj
|
|
198
186
|
#
|
199
187
|
# * *Raises* :
|
200
188
|
#
|
201
|
-
def
|
189
|
+
def _setup_data_where?(order, data_to_check)
|
190
|
+
res = _setup_data_position?(order, data_to_check)
|
191
|
+
|
192
|
+
return nil if res.nil?
|
193
|
+
|
194
|
+
after_index, before_index, after, before = res
|
195
|
+
|
196
|
+
if after_index.nil? || before_index.nil?
|
197
|
+
return before_index if after_index.nil?
|
198
|
+
return after_index
|
199
|
+
end
|
200
|
+
|
201
|
+
if after_index[0] > before_index[0] ||
|
202
|
+
(after_index[0] == before_index[0] && after_index[1] > before_index[1])
|
203
|
+
PrcLib.warning("Unable to insert '%s' attribute before '%s' (pos %s)"\
|
204
|
+
" and after '%s' (pos %s). "\
|
205
|
+
"'%s' will be added at the end.",
|
206
|
+
data_to_check, before, before_index, after, after_index,
|
207
|
+
data_to_check)
|
208
|
+
return nil
|
209
|
+
end
|
210
|
+
|
211
|
+
after_index
|
212
|
+
end
|
213
|
+
|
214
|
+
def _setup_data_position?(order, data_to_check)
|
202
215
|
meta = _get_meta_data(data_to_check)
|
203
|
-
return
|
216
|
+
return nil if meta.nil?
|
217
|
+
return nil unless meta.rh_exist?(:after) || meta.rh_exist?(:before)
|
218
|
+
|
219
|
+
after = meta.rh_get(:after)
|
220
|
+
before = meta.rh_get(:before)
|
221
|
+
after_index = nil
|
222
|
+
before_index = nil
|
223
|
+
|
224
|
+
order.each do |k, attrs|
|
225
|
+
attrs.each do |attr_name|
|
226
|
+
after_index = [k, attrs.index(attr_name) + 1] if after == attr_name
|
227
|
+
before_index = [k, attrs.index(attr_name)] if before == attr_name
|
228
|
+
end
|
229
|
+
end
|
204
230
|
|
205
|
-
|
206
|
-
|
207
|
-
|
231
|
+
return nil if after_index.nil? && before_index.nil?
|
232
|
+
|
233
|
+
[after_index, before_index, after, before]
|
208
234
|
end
|
209
235
|
|
210
236
|
# check if a config data is already listed in the setup list at a specific
|
@@ -217,149 +243,11 @@ module Lorj
|
|
217
243
|
# * *returns* :
|
218
244
|
# - true if found. false otherwise.
|
219
245
|
def _setup_attr_already_added?(order_array, data_to_check)
|
220
|
-
order_array.
|
246
|
+
order_array.each_key do |order_index|
|
221
247
|
attributes = order_array[order_index]
|
222
248
|
return true unless attributes.index(data_to_check).nil?
|
223
249
|
end
|
224
250
|
false
|
225
251
|
end
|
226
|
-
|
227
|
-
# Add the attribute parameter to setup list
|
228
|
-
# at the right position, determined by it dependencies.
|
229
|
-
#
|
230
|
-
# The attribute can be added only if :account is true. Data set in
|
231
|
-
# the application defaults.yaml:
|
232
|
-
# :sections/<Section>/<Attribute>/:account: true
|
233
|
-
#
|
234
|
-
# Attributes dependency is first loaded by the lorj object model
|
235
|
-
# Each attributes can add more dependency thanks to the application
|
236
|
-
# defaults.yaml:
|
237
|
-
# :sections/<Section>/<Attribute>/:depends_on (Array of attributes)
|
238
|
-
#
|
239
|
-
# The attribute step can be set from defaults.yaml as well:
|
240
|
-
# :sections/<Section>/<Attribute>/:ask_step (FixNum)
|
241
|
-
#
|
242
|
-
# The attribute can be asked at a determined index, set in
|
243
|
-
# the application defaults.yaml:
|
244
|
-
# :sections/<Section>/<Attribute>/:ask_sort: (FixNum)
|
245
|
-
#
|
246
|
-
# parameters :
|
247
|
-
# - +setup_steps+ : setup steps
|
248
|
-
# - +attr_name+ : Attribute to add
|
249
|
-
def _setup_obj_param_is_data(setup_steps, inspected_objects, attr_name)
|
250
|
-
if inspected_objects.include?(attr_name)
|
251
|
-
Lorj.debug(2, "#{attr_name} is already asked. Ignored.")
|
252
|
-
return false
|
253
|
-
end
|
254
|
-
|
255
|
-
meta = _get_meta_data(attr_name)
|
256
|
-
return false unless meta.is_a?(Hash)
|
257
|
-
|
258
|
-
ask_step = 0
|
259
|
-
ask_step = meta[:ask_step] if meta[:ask_step].is_a?(Fixnum)
|
260
|
-
|
261
|
-
Lorj.debug(3, "#{attr_name} is part of setup step #{ask_step}")
|
262
|
-
order_array = setup_steps[ask_step][:order]
|
263
|
-
|
264
|
-
unless meta[:account].is_a?(TrueClass)
|
265
|
-
Lorj.debug(2, "'%s' won't be asked during setup."\
|
266
|
-
' :account = true not set.', attr_name)
|
267
|
-
return false
|
268
|
-
end
|
269
|
-
|
270
|
-
level_index = _setup_level_index(order_array, attr_name,
|
271
|
-
meta[:depends_on])
|
272
|
-
|
273
|
-
return true if order_array[level_index].include?(attr_name)
|
274
|
-
|
275
|
-
level = _setup_attr_add(order_array[level_index], attr_name, meta,
|
276
|
-
level_index)
|
277
|
-
Lorj.debug(3, "S%s/L%s/%s: '%s' added in setup list. ",
|
278
|
-
ask_step, level, level_index, attr_name)
|
279
|
-
|
280
|
-
true
|
281
|
-
end
|
282
|
-
|
283
|
-
# Function to identify level index for an attribute.
|
284
|
-
#
|
285
|
-
# parameters:
|
286
|
-
# - +order_array+ : array of levels of attributes ordered.
|
287
|
-
# - +attr_name+ : attribute name
|
288
|
-
# - +depends_on+ : Dependency Array.
|
289
|
-
#
|
290
|
-
# return:
|
291
|
-
# - level_index to use.
|
292
|
-
def _setup_level_index(order_array, attr_name, depends_on)
|
293
|
-
if !depends_on.is_a?(Array)
|
294
|
-
PrcLib.warning("'%s' depends_on definition have to be"\
|
295
|
-
' an array.',
|
296
|
-
attr_name) unless depends_on.nil?
|
297
|
-
0
|
298
|
-
else
|
299
|
-
_setup_find_dep_level(order_array, depends_on)
|
300
|
-
end
|
301
|
-
end
|
302
|
-
|
303
|
-
# Function to add an attribute to the level layer of the setup array .
|
304
|
-
#
|
305
|
-
# parameters:
|
306
|
-
# - +level_array+ : array of attributes ordered.
|
307
|
-
# - +attr_name+ : attribute name
|
308
|
-
# - +order_index+ : order index where to insert the attribute.
|
309
|
-
#
|
310
|
-
def _setup_attr_add(level_array, attr_name, meta, level_index)
|
311
|
-
if meta[:ask_sort].is_a?(Fixnum)
|
312
|
-
order_index = meta[:ask_sort]
|
313
|
-
_setup_attr_add_at(level_array, attr_name, order_index)
|
314
|
-
Lorj.debug(3, "S%s/L%s/O%s: '%s' added in setup list. ",
|
315
|
-
meta[:ask_step], level_index, order_index, attr_name)
|
316
|
-
"O#{level_index}"
|
317
|
-
else
|
318
|
-
level_array << attr_name
|
319
|
-
Lorj.debug(3, "S%s/L%s/Last: '%s' added in setup list.",
|
320
|
-
meta[:ask_step], level_index, attr_name)
|
321
|
-
'Last'
|
322
|
-
end
|
323
|
-
end
|
324
|
-
|
325
|
-
# Function to insert an attribute at a specific order.
|
326
|
-
# It will shift other attributes if needed.
|
327
|
-
#
|
328
|
-
# parameters:
|
329
|
-
# - +level_array+ : array of attributes ordered.
|
330
|
-
# - +attr_name+ : attribute name
|
331
|
-
# - +order_index+ : order index where to insert the attribute.
|
332
|
-
#
|
333
|
-
def _setup_attr_add_at(level_array, attr_name, order_index)
|
334
|
-
if level_array[order_index].nil?
|
335
|
-
level_array[order_index] = attr_name
|
336
|
-
else
|
337
|
-
level_array.insert(order_index, attr_name)
|
338
|
-
end
|
339
|
-
end
|
340
|
-
|
341
|
-
# Search for the lowest step to ask an attribute, thanks to dependencies.
|
342
|
-
#
|
343
|
-
# parameters:
|
344
|
-
# - +order_array+ : Array of attributes, at 2 dimensions [step then order]
|
345
|
-
# - +attr_dep+ : Array of attributes/objects needed before this
|
346
|
-
# attribute.
|
347
|
-
#
|
348
|
-
# returns:
|
349
|
-
# - the lowest step index where the attribute can be added.
|
350
|
-
def _setup_find_dep_level(order_array, attr_dep)
|
351
|
-
level_index = 0
|
352
|
-
|
353
|
-
attr_dep.each do |depend_key|
|
354
|
-
order_array.each_index do |iCurLevel|
|
355
|
-
if order_array[iCurLevel].include?(depend_key)
|
356
|
-
level_index = [level_index, iCurLevel + 1].max
|
357
|
-
end
|
358
|
-
end
|
359
|
-
order_array[level_index] = [] if order_array[level_index].nil?
|
360
|
-
end
|
361
|
-
|
362
|
-
level_index
|
363
|
-
end
|
364
252
|
end
|
365
253
|
end
|
data/lib/core/core_setup_ask.rb
CHANGED
@@ -57,6 +57,8 @@ module Lorj
|
|
57
57
|
section = _get_account_section(data)
|
58
58
|
# We set the value only if there is a value entered by the user.
|
59
59
|
unless section.nil? || value.nil?
|
60
|
+
Lorj.debug(3, "'%s'/'%s': Setting value to '%s'",
|
61
|
+
section, data, value)
|
60
62
|
@config.set(data, value, :name => 'account', :section => section)
|
61
63
|
end
|
62
64
|
|
@@ -130,7 +132,7 @@ module Lorj
|
|
130
132
|
# - +desc+ : Data description
|
131
133
|
# - +options+ : Used when user have to enter a string instead of
|
132
134
|
# selecting from a list.
|
133
|
-
#
|
135
|
+
# - +:default_value+ : predefined default value.
|
134
136
|
#
|
135
137
|
# if data model defines :default_value. => choose it
|
136
138
|
# In this last case, the :default_value is interpreted by ERB.
|
@@ -159,12 +161,14 @@ module Lorj
|
|
159
161
|
default = result[:default_value] unless result[:default_value].nil?
|
160
162
|
|
161
163
|
begin
|
164
|
+
Lorj.debug(3, "'%s': ERB on default value '%s'", data, default)
|
162
165
|
default = erb(default) unless default.nil?
|
163
166
|
rescue => e
|
164
167
|
PrcLib.warning("ERB error with :%s/:default_value '%s'.\n%s",
|
165
168
|
data, result[:default_value], e.message)
|
166
169
|
else
|
167
170
|
default = nil if default == ''
|
171
|
+
Lorj.debug(3, "'%s': default value '%s'", data, default)
|
168
172
|
options[:default_value] = default
|
169
173
|
end
|
170
174
|
|
@@ -207,6 +211,11 @@ module Lorj
|
|
207
211
|
#
|
208
212
|
def _setup_choose_data_from_list(data, desc, list, options)
|
209
213
|
default = @config.get(data, options[:default_value])
|
214
|
+
Lorj.debug(3, "'%s': Getting value from config - '%s'(from '%s' - "\
|
215
|
+
"sections '%s')"\
|
216
|
+
" (default is '%s')",
|
217
|
+
data, default, @config.where?(data), Lorj.data.sections(data),
|
218
|
+
options[:default_value])
|
210
219
|
|
211
220
|
say_msg = format("Select '%s' from the list:", desc)
|
212
221
|
say_msg += format(' |%s|', default) unless default.nil?
|
@@ -259,18 +268,24 @@ module Lorj
|
|
259
268
|
if default.nil? && !options[:default_value].nil?
|
260
269
|
begin
|
261
270
|
default = erb(options[:default_value])
|
271
|
+
Lorj.debug(3, "'%s': Running ERB for default_value '%s' = '%s'",
|
272
|
+
data, options[:default_value], default)
|
262
273
|
rescue => e
|
263
274
|
PrcLib.warning("ERB error with :%s/:default_value '%s'.\n%s",
|
264
275
|
data, options[:default_value], e.message)
|
265
276
|
end
|
266
277
|
end
|
267
|
-
|
278
|
+
ask_default = @config.get(data, default)
|
279
|
+
Lorj.debug(3, "'%s': Getting value from config - '%s'(from '%s' - "\
|
280
|
+
"sections '%s') (default is '%s')",
|
281
|
+
data, ask_default, @config.where?(data),
|
282
|
+
Lorj.data.sections(data), default)
|
268
283
|
|
269
284
|
# validate_proc = options[:validate_function]
|
270
285
|
proc_ask = options[:ask_function]
|
271
286
|
|
272
287
|
if proc_ask.nil?
|
273
|
-
value = _ask(desc,
|
288
|
+
value = _ask(desc, ask_default, valid_regex, is_encrypted, is_required)
|
274
289
|
else
|
275
290
|
value = @process.method(proc_ask)
|
276
291
|
end
|