lorj 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.gitreview +4 -0
- data/Gemfile +25 -0
- data/Gemfile.lock +34 -0
- data/LICENSE.txt +14 -0
- data/README.md +652 -0
- data/Rakefile +24 -0
- data/bin/cloud_test.rb +81 -0
- data/example/students_1/process/Students.rb +20 -0
- data/example/students_1/students.rb +16 -0
- data/example/students_2/process/Students.rb +27 -0
- data/example/students_2/students.rb +36 -0
- data/example/students_3/controller/yaml_students.rb +94 -0
- data/example/students_3/controller/yaml_students_controller.rb +123 -0
- data/example/students_3/process/students.rb +118 -0
- data/example/students_3/students.rb +93 -0
- data/example/students_4/controller/yaml_students.rb +82 -0
- data/example/students_4/controller/yaml_students_controller.rb +141 -0
- data/example/students_4/process/students.rb +112 -0
- data/example/students_4/students.rb +103 -0
- data/example/yaml_students/students.rb +78 -0
- data/example/yaml_students/yaml_students.rb +115 -0
- data/lib/concept.md +111 -0
- data/lib/core/core.rb +723 -0
- data/lib/core/definition.rb +505 -0
- data/lib/core/definition_internal.rb +338 -0
- data/lib/core/lorj-basecontroller.rb +90 -0
- data/lib/core/lorj-basedefinition.rb +1079 -0
- data/lib/core/lorj-baseprocess.rb +231 -0
- data/lib/core/lorj-data.rb +567 -0
- data/lib/core/lorj-keypath.rb +115 -0
- data/lib/core_process/CloudProcess.rb +334 -0
- data/lib/core_process/global_process.rb +406 -0
- data/lib/core_process/network_process.rb +603 -0
- data/lib/img/.directory +4 -0
- data/lib/img/account_data_access.png +0 -0
- data/lib/img/config_data_access.png +0 -0
- data/lib/img/forj-lib-concept.png +0 -0
- data/lib/lorj/version.rb +3 -0
- data/lib/lorj.rb +51 -0
- data/lib/prc-account.rb +339 -0
- data/lib/prc-config.rb +1023 -0
- data/lib/prc-logging.rb +183 -0
- data/lib/prc.rb +108 -0
- data/lib/providers/hpcloud/Hpcloud.rb +419 -0
- data/lib/providers/hpcloud/compute.rb +108 -0
- data/lib/providers/hpcloud/network.rb +117 -0
- data/lib/providers/hpcloud/security_groups.rb +67 -0
- data/lib/providers/mock/Mock.rb +141 -0
- data/lib/providers/openstack/Openstack.rb +47 -0
- data/lib/providers/templates/compute.rb +42 -0
- data/lib/providers/templates/core.rb +61 -0
- data/lib/providers/templates/network.rb +33 -0
- data/lorj-spec/defaults.yaml +26 -0
- data/lorj.gemspec +39 -0
- data/spec/forj-account_spec.rb +75 -0
- data/spec/forj-config_spec.rb +196 -0
- metadata +164 -0
@@ -0,0 +1,505 @@
|
|
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
|
+
# Module Lorj which contains several classes.
|
19
|
+
#
|
20
|
+
# Those classes describes :
|
21
|
+
# - processes (BaseProcess) : How to create/delete/edit/query object.
|
22
|
+
# - controler (BaseControler) : If a provider is defined, define how will do object creation/etc...
|
23
|
+
# - definition(BaseDefinition): Functions to declare objects, query/data mapping and setup
|
24
|
+
# this task to make it to work.
|
25
|
+
module Lorj
|
26
|
+
class BaseDefinition
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
###################################################
|
31
|
+
# Class management Section
|
32
|
+
###################################################
|
33
|
+
|
34
|
+
# Meta Object declaration structure
|
35
|
+
# <Object>
|
36
|
+
# :query_mapping List of keypath mapped.
|
37
|
+
# <keypath> = <keypath mapped>
|
38
|
+
# :lambdas:
|
39
|
+
# :create_e: function to call at 'Create' task
|
40
|
+
# :delete_e: function to call at 'Delete' task
|
41
|
+
# :update_e: function to call at 'Update' task
|
42
|
+
# :get_e: function to call at 'Get' task
|
43
|
+
# :query_e: function to call at 'Query' task
|
44
|
+
# :value_mapping: Define list of Object's key values mapping.
|
45
|
+
# <keypath> key value mapping lists
|
46
|
+
# <value> = <map> Define the value mapping.
|
47
|
+
# :returns
|
48
|
+
# <keypath> key value to extract from controller object.
|
49
|
+
# :params: Defines CloudData (:data) or CloudObj (:CloudObj) needs by the <Object>
|
50
|
+
# :keys: Contains keys in a tree of hash.
|
51
|
+
# <keypath>: String. One element (string with : and /) of :list defining the key
|
52
|
+
# :type: :data or :CloudObj
|
53
|
+
# :for: Array of events which requires the data or CloudObj to work.
|
54
|
+
# :mapping: To automatically create a provider hash data mapped (hdata).
|
55
|
+
# :required: True if this parameter is required.
|
56
|
+
# :extract_from: Array. Build the keypath value from another hParams value.
|
57
|
+
# Ex: This example will extract :id from :security_groups object
|
58
|
+
# :extract_from => [:security_groups, :id]
|
59
|
+
#
|
60
|
+
@@meta_obj = {}
|
61
|
+
|
62
|
+
# meta data are defined in defaults.yaml and loaded in Lorj::Default class definition
|
63
|
+
# Cloud provider can redefine ForjData defaults and add some extra parameters.
|
64
|
+
# To get Application defaults, read defaults.yaml, under :sections:
|
65
|
+
# <Section>:
|
66
|
+
# <Data>: Required. Symbol/String. default: nil
|
67
|
+
# => Data name. This symbol must be unique, across sections.
|
68
|
+
# :desc: Required. String. default: nil
|
69
|
+
# => Description
|
70
|
+
# :readonly: Optional. true/false. Default: false
|
71
|
+
# => oForjConfig.set() will fail if readonly is true.
|
72
|
+
# Can be set, only thanks to oForjConfig.setup()
|
73
|
+
# or using private oForjConfig._set()
|
74
|
+
# :account_exclusive: Optional. true/false. Default: false
|
75
|
+
# => Only oConfig.account_get/set() can handle the value
|
76
|
+
# oConfig.set/get cannot.
|
77
|
+
# :account: Optional. default: False
|
78
|
+
# => setup will configure the account with this <Data>
|
79
|
+
# :ask_sort: Number which represents the ask order in the step group. (See /:setup/:ask_step for details)
|
80
|
+
# :after: <Data> Name of the previous <Data> to ask before the current one.
|
81
|
+
# :depends_on:
|
82
|
+
# => Identify :data type required to be set before the current one.
|
83
|
+
# :default_value: Default value at setup time. This is not necessarily the Application default value (See /:default)
|
84
|
+
# :validate: Regular expression to validate end user input during setup.
|
85
|
+
# :value_mapping: list of values to map as defined by the controller
|
86
|
+
# :controller: mapping for get controller value from process values
|
87
|
+
# <value> : <map> value map equivalence. See data_value_mapping function
|
88
|
+
# :process: mapping for get process value from controller values
|
89
|
+
# <value> : <map> value map equivalence. See data_value_mapping function
|
90
|
+
# :defaut: Default value
|
91
|
+
# :list_values: Defines a list of valid values for the current data.
|
92
|
+
# :query_type :controller_call to execute a function defined in the controller object.
|
93
|
+
# :process_call to execute a function defined in the process object.
|
94
|
+
# :values to get list of values from :values.
|
95
|
+
# :object Object to load before calling the function. Only :query_type = :*_call
|
96
|
+
# :query_call Symbol. function name to call. Only :query_type = :*_call
|
97
|
+
# function must return an Array.
|
98
|
+
# :query_params Hash. Controler function parameters. Only :query_type = :*_call
|
99
|
+
# :validate :list_strict. valid only if value is one of those listed.
|
100
|
+
# :values:
|
101
|
+
# to retrieve from.
|
102
|
+
# otherwise define simply a list of possible values.
|
103
|
+
# :ask_step: Step number. By default, setup will determine the step, thanks to meta lorj object dependencies tree.
|
104
|
+
# This number start at 0. Each step can be defined by /:setup/:ask_step/<steps> list.
|
105
|
+
#
|
106
|
+
# :setup: This section describes group of fields to ask, step by step.
|
107
|
+
# :ask_step: Define an Array of setup steps to ask to the end user. The step order is respected, and start at 0
|
108
|
+
# - :desc: Define the step description
|
109
|
+
# :explanation: |- Define a multiline explanation. This is printed out in brown color.
|
110
|
+
# :add: Define a list of additionnal fields to ask.
|
111
|
+
# - <Data> Data to ask.
|
112
|
+
#
|
113
|
+
# :default: List of <Data> application default values.
|
114
|
+
# <Data> : Value to use at the config application level.
|
115
|
+
@@meta_data = {}
|
116
|
+
|
117
|
+
# The Generic Process can pre-define some data and value (function predefine_data)
|
118
|
+
# The Generic Process (and external framework call) only knows about Generic data.
|
119
|
+
# information used
|
120
|
+
#
|
121
|
+
@@meta_predefined_values = {}
|
122
|
+
|
123
|
+
# <Data>: Data name
|
124
|
+
# :values: List of possible values
|
125
|
+
# <Value>: Value Name attached to the data
|
126
|
+
# options: Options
|
127
|
+
# :desc: Description of that predefine value.
|
128
|
+
|
129
|
+
@@Context = {
|
130
|
+
:oCurrentObj => nil, # Defines the Current Object to manipulate
|
131
|
+
:needs_optional => nil, # set optional to true for any next needs declaration
|
132
|
+
:ClassProcess => nil # Current Process Class declaration
|
133
|
+
}
|
134
|
+
|
135
|
+
# Available functions for:
|
136
|
+
# - BaseDefinition class declaration
|
137
|
+
# - Controler (derived from BaseDefinition) class declaration
|
138
|
+
|
139
|
+
@@query_auto_map = false
|
140
|
+
|
141
|
+
def self.current_process (cProcessClass)
|
142
|
+
@@Context[:ClassProcess] = cProcessClass
|
143
|
+
end
|
144
|
+
|
145
|
+
def self.obj_needs_optional
|
146
|
+
@@Context[:needs_optional] = true
|
147
|
+
end
|
148
|
+
|
149
|
+
def self.obj_needs_requires
|
150
|
+
@@Context[:needs_optional] = false
|
151
|
+
end
|
152
|
+
|
153
|
+
def self.process_default(hOptions)
|
154
|
+
aSupportedOptions = [:use_controller]
|
155
|
+
unless hOptions.nil?
|
156
|
+
hOptions.each_key { | key |
|
157
|
+
case key
|
158
|
+
when :use_controller
|
159
|
+
value = Lorj::rhGet(hOptions, :use_controller)
|
160
|
+
next unless value.is_a?(TrueClass) or value.is_a?(FalseClass)
|
161
|
+
Lorj::rhSet(@@Context, hOptions[key], :options, key)
|
162
|
+
else
|
163
|
+
raise Lorj::PrcError.new, "Unknown default process options '%s'. Supported are '%s'" % [key, aSupportedOptions.join(',')]
|
164
|
+
end
|
165
|
+
}
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|
169
|
+
|
170
|
+
# Defines Object and connect to functions events
|
171
|
+
def self.define_obj(sCloudObj, hParam = nil)
|
172
|
+
return nil if not sCloudObj
|
173
|
+
return nil if not [String, Symbol].include?(sCloudObj.class)
|
174
|
+
|
175
|
+
aCaller = caller
|
176
|
+
aCaller.pop
|
177
|
+
|
178
|
+
sCloudObj = sCloudObj.to_sym if sCloudObj.class == String
|
179
|
+
@@Context[:oCurrentObj] = sCloudObj
|
180
|
+
@@Context[:needs_optional] = false
|
181
|
+
@@Context[:needs_setup] = false
|
182
|
+
bController = Lorj::rhGet(@@Context, :options, :use_controller)
|
183
|
+
bController = true if bController.nil?
|
184
|
+
|
185
|
+
if not [Hash].include?(hParam.class)
|
186
|
+
if Lorj::rhExist?(@@meta_obj, sCloudObj) != 1
|
187
|
+
raise Lorj::PrcError.new(), "New undefined object '%s' requires at least one handler. Ex: define_obj :%s, :create_e => myhandler " % [sCloudObj, sCloudObj]
|
188
|
+
end
|
189
|
+
hParam = {}
|
190
|
+
end
|
191
|
+
|
192
|
+
oCloudObj = Lorj::rhGet(@@meta_obj, sCloudObj)
|
193
|
+
if not oCloudObj
|
194
|
+
oCloudObj = {
|
195
|
+
:lambdas => {:create_e => nil, :delete_e => nil, :update_e => nil, :get_e => nil, :query_e => nil, :get_attr_e => nil},
|
196
|
+
:params => {},
|
197
|
+
:options => {:controller => bController },
|
198
|
+
:query_mapping => { ":id" => ":id", ":name" => ":name"},
|
199
|
+
:returns => {":id" => ":id", ":name" => ":name"}
|
200
|
+
}
|
201
|
+
msg = nil
|
202
|
+
else
|
203
|
+
msg = ""
|
204
|
+
end
|
205
|
+
|
206
|
+
sObjectName = "'%s.%s'" % [self.class, sCloudObj]
|
207
|
+
|
208
|
+
# Checking hParam data
|
209
|
+
if not Lorj::rhGet(hParam, :nohandler)
|
210
|
+
hParam.each_key do | key |
|
211
|
+
raise Lorj::PrcError.new(), "'%s' parameter is invalid. Use '%s'" % [key, oCloudObj[:lambdas].keys.join(', ')], aCaller if Lorj::rhExist?(oCloudObj, :lambdas, key)!= 2
|
212
|
+
end
|
213
|
+
msg = "%-28s object declared." % [sObjectName] if not msg
|
214
|
+
else
|
215
|
+
msg = "%-28s meta object declared." % [sObjectName] if not msg
|
216
|
+
end
|
217
|
+
Lorj.debug(2, msg) if msg != ""
|
218
|
+
|
219
|
+
# Setting procs
|
220
|
+
Lorj::rhGet(oCloudObj, :lambdas).each_key { |key|
|
221
|
+
next if not hParam.key?(key)
|
222
|
+
|
223
|
+
if not @@Context[:ClassProcess].instance_methods.include?(hParam[key])
|
224
|
+
raise Lorj::PrcError.new(), "'%s' parameter requires a valid instance method '%s' in the process '%s'." % [key, hParam[key], @@Context[:ClassProcess]], aCaller
|
225
|
+
end
|
226
|
+
if hParam[key] == :default
|
227
|
+
# By default, we use the event name as default function to call.
|
228
|
+
# Those function are predefined in ForjController
|
229
|
+
# The Provider needs to derive from ForjController and redefine those functions.
|
230
|
+
oCloudObj[:lambdas][key] = key
|
231
|
+
else
|
232
|
+
# If needed, ForjProviver redefined can contains some additionnal functions
|
233
|
+
# to call.
|
234
|
+
oCloudObj[:lambdas][key] = hParam[key]
|
235
|
+
end
|
236
|
+
}
|
237
|
+
Lorj::rhSet(@@meta_obj, oCloudObj, sCloudObj)
|
238
|
+
end
|
239
|
+
|
240
|
+
def self.def_query_attribute(key)
|
241
|
+
self.query_mapping(key, key)
|
242
|
+
end
|
243
|
+
|
244
|
+
def self.query_mapping(key, map)
|
245
|
+
return nil if not [String, Symbol].include?(key.class)
|
246
|
+
return nil if not [NilClass, Symbol, String].include?(map.class)
|
247
|
+
|
248
|
+
aCaller = caller
|
249
|
+
aCaller.pop
|
250
|
+
|
251
|
+
raise Lorj::PrcError.new(), "%s: No Object defined. Missing define_obj?" % [ self.class], aCaller if @@Context[:oCurrentObj].nil?
|
252
|
+
|
253
|
+
sCloudObj = @@Context[:oCurrentObj]
|
254
|
+
oKeyPath = KeyPath.new(key)
|
255
|
+
oMapPath = KeyPath.new(map)
|
256
|
+
|
257
|
+
@@Context[:oCurrentKey] = oKeyPath
|
258
|
+
|
259
|
+
Lorj::rhSet(@@meta_obj, oMapPath.sFullPath, sCloudObj, :query_mapping, oKeyPath.sFullPath)
|
260
|
+
end
|
261
|
+
|
262
|
+
# Available functions exclusively for Controler (derived from BaseDefinition) class declaration
|
263
|
+
|
264
|
+
# Following functions are related to Object Attributes
|
265
|
+
# ----------------------------------------------------
|
266
|
+
|
267
|
+
# Defines Object CloudData/CloudObj dependency
|
268
|
+
def self.obj_needs(sType, sParam, hParams = {})
|
269
|
+
return nil if not [String, Symbol].include?(sType.class)
|
270
|
+
return nil if not [String, Symbol, Array].include?(sParam.class)
|
271
|
+
|
272
|
+
hParams = {} if not hParams
|
273
|
+
|
274
|
+
hParams[:required] = not(@@Context[:needs_optional]) if Lorj::rhExist?(hParams, :required) != 1
|
275
|
+
|
276
|
+
aCaller = caller
|
277
|
+
aCaller.pop
|
278
|
+
|
279
|
+
raise Lorj::PrcError.new(), "%s: No Object defined. Missing define_obj?" % [ self.class], aCaller if @@Context[:oCurrentObj].nil?
|
280
|
+
|
281
|
+
sCloudObj = @@Context[:oCurrentObj]
|
282
|
+
|
283
|
+
aForEvents = Lorj::rhGet(@@meta_obj, sCloudObj, :lambdas).keys
|
284
|
+
hParams = hParams.merge({ :for => aForEvents}) if not hParams.key?(:for)
|
285
|
+
sType = sType.to_sym if sType.class == String
|
286
|
+
|
287
|
+
|
288
|
+
raise Lorj::PrcError.new(), "%s: '%s' not declared. Missing define_obj(%s)?" % [ self.class, sCloudObj, sCloudObj], aCaller if Lorj::rhExist?(@@meta_obj, sCloudObj) != 1
|
289
|
+
|
290
|
+
oObjTopParam = Lorj::rhGet(@@meta_obj, sCloudObj, :params)
|
291
|
+
if not oObjTopParam.key?(:keys)
|
292
|
+
# Initialize top structure
|
293
|
+
|
294
|
+
oObjTopParam.merge!({ :keys => {} })
|
295
|
+
end
|
296
|
+
|
297
|
+
oKeyPath = KeyPath.new(sParam)
|
298
|
+
sKeyAccess = oKeyPath.sFullPath
|
299
|
+
|
300
|
+
@@Context[:oCurrentKey] = oKeyPath
|
301
|
+
|
302
|
+
oCloudObjParam = Lorj::rhGet(oObjTopParam, :keys, sKeyAccess)
|
303
|
+
if oCloudObjParam.nil?
|
304
|
+
sMsgAction = "New"
|
305
|
+
oObjTopParam[:keys][sKeyAccess] = {}
|
306
|
+
oCloudObjParam = oObjTopParam[:keys][sKeyAccess]
|
307
|
+
else
|
308
|
+
sMsgAction = "Upd"
|
309
|
+
end
|
310
|
+
sObjectName = "'%s.%s'" % [self.class, sCloudObj]
|
311
|
+
case sType
|
312
|
+
when :data
|
313
|
+
if Lorj::Default.meta_exist?(sParam)
|
314
|
+
Lorj.debug(2, "%-28s: %s predefined config '%s'." % [sObjectName, sMsgAction, sParam])
|
315
|
+
else
|
316
|
+
Lorj.debug(2, "%-28s: %s runtime config '%s'." % [sObjectName, sMsgAction, sParam])
|
317
|
+
end
|
318
|
+
oCloudObjParam.merge!( hParams.merge({:type => sType}) ) # Merge from predefined params, but ensure type is never updated.
|
319
|
+
when :CloudObject
|
320
|
+
raise Lorj::PrcError.new(), "%s: '%s' not declared. Missing define_obj(%s)?" % [self.class, sParam, sParam], aCaller if not @@meta_obj.key?(sParam)
|
321
|
+
oCloudObjParam.merge!( hParams.merge({:type => sType}) ) # Merge from predefined params, but ensure type is never updated.
|
322
|
+
else
|
323
|
+
raise Lorj::PrcError.new(), "%s: Object parameter type '%s' unknown." % [ self.class, sType ], aCaller
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
# Define the hdata values to build for the controller automatically
|
328
|
+
# Input:
|
329
|
+
# - sParam: Data name to add in hdata controller.
|
330
|
+
# - hParams: supports following hash values:
|
331
|
+
# - :mapping (merged in @@meta_obj://<Object>/:params/:keys/<keypath>/:mapping)
|
332
|
+
#
|
333
|
+
|
334
|
+
def self.set_hdata(sParam, hParams = {})
|
335
|
+
return nil if not [String, Symbol, Array].include?(sParam.class)
|
336
|
+
|
337
|
+
hParams = {} if not hParams
|
338
|
+
|
339
|
+
aCaller = caller
|
340
|
+
aCaller.pop
|
341
|
+
|
342
|
+
raise Lorj::PrcError.new(), "%s: No Object defined. Missing define_obj?" % [ self.class], aCaller if @@Context[:oCurrentObj].nil?
|
343
|
+
sCloudObj = @@Context[:oCurrentObj]
|
344
|
+
|
345
|
+
raise Lorj::PrcError.new(), "%s: '%s' not declared. Missing define_obj(%s)?" % [ self.class, sCloudObj, sCloudObj], aCaller if Lorj::rhExist?(@@meta_obj, sCloudObj) != 1
|
346
|
+
|
347
|
+
oKeyPath = KeyPath.new(sParam)
|
348
|
+
sKeyAccess = oKeyPath.sFullPath
|
349
|
+
|
350
|
+
# @@meta_obj://<Object>/:params/:keys/<keypath> must exist.
|
351
|
+
oCloudObjParam = Lorj::rhGet(@@meta_obj, sCloudObj, :params, :keys, sKeyAccess)
|
352
|
+
|
353
|
+
sMapping = sParam
|
354
|
+
sMapping = hParams[:mapping] unless hParams[:mapping].nil?
|
355
|
+
oCloudObjParam[:mapping] = sMapping
|
356
|
+
|
357
|
+
sObjectName = "'%s.%s'" % [self.class, sCloudObj]
|
358
|
+
Lorj.debug(2, "%-28s: hdata set '%s' => '%s'" % [sObjectName, sParam, sMapping])
|
359
|
+
end
|
360
|
+
|
361
|
+
|
362
|
+
def self.attr_value_mapping(value, map)
|
363
|
+
return nil if not [String, Symbol].include?(value.class)
|
364
|
+
return nil if not [NilClass, Symbol, String].include?(map.class)
|
365
|
+
|
366
|
+
aCaller = caller
|
367
|
+
aCaller.pop
|
368
|
+
|
369
|
+
sCloudObj = @@Context[:oCurrentObj]
|
370
|
+
raise Lorj::PrcError.new, "attr_value_mapping: mapping '%s' needs object context definition. You need to call define_obj to get the context." % value if sCloudObj.nil?
|
371
|
+
|
372
|
+
oKeypath = @@Context[:oCurrentKey]
|
373
|
+
raise Lorj::PrcError.new, "attr_value_mapping: mapping '%s' needs object data context definition. You need to call define_obj, then obj_needs to get the context." % value if oKeypath.nil?
|
374
|
+
|
375
|
+
keypath = oKeypath.sFullPath
|
376
|
+
Lorj.debug(2, "%s-%s: Value mapping definition '%s' => '%s'" % [sCloudObj, oKeypath.to_s, value, map])
|
377
|
+
Lorj::rhSet(@@meta_obj, map, sCloudObj, :value_mapping, keypath, value)
|
378
|
+
end
|
379
|
+
|
380
|
+
def self.def_attribute(key, options = nil)
|
381
|
+
self.get_attr_mapping(key, options)
|
382
|
+
#~ self.def_query_attribute(key) unless options and options.key?(:not_queriable) and options[:not_queriable]== true
|
383
|
+
end
|
384
|
+
|
385
|
+
# Function used by the controler to define mapping.
|
386
|
+
# By default, any attributes are queriable as well. No need to call
|
387
|
+
# query_mapping
|
388
|
+
def self.get_attr_mapping(key, map = nil, options = nil)
|
389
|
+
return nil if not [String, Symbol].include?(key.class)
|
390
|
+
return nil if not [NilClass, Symbol, String, Array].include?(map.class)
|
391
|
+
|
392
|
+
aCaller = caller
|
393
|
+
aCaller.pop
|
394
|
+
|
395
|
+
raise Lorj::PrcError.new(), "%s: No Object defined. Missing define_obj?" % [ self.class], aCaller if @@Context[:oCurrentObj].nil?
|
396
|
+
|
397
|
+
sCloudObj = @@Context[:oCurrentObj]
|
398
|
+
oKeyPath = KeyPath.new(key)
|
399
|
+
|
400
|
+
if map.nil?
|
401
|
+
oMapPath = oKeyPath
|
402
|
+
map = oMapPath.sKey
|
403
|
+
else
|
404
|
+
oMapPath = KeyPath.new(map)
|
405
|
+
end
|
406
|
+
|
407
|
+
Lorj::rhSet(@@meta_obj, oMapPath.sFullPath, sCloudObj, :returns, oKeyPath.sFullPath)
|
408
|
+
@@Context[:oCurrentKey] = oKeyPath
|
409
|
+
if oMapPath == oKeyPath
|
410
|
+
Lorj::debug(4, "%s: Defining object attribute '%s'" % [sCloudObj, oKeyPath.sFullPath])
|
411
|
+
else
|
412
|
+
Lorj::debug(4, "%s: Defining object attribute mapping '%s' => '%s'" % [sCloudObj, oKeyPath.sFullPath, oMapPath.sFullPath])
|
413
|
+
end
|
414
|
+
|
415
|
+
self.query_mapping(key, map) unless options and options.key?(:not_queriable) and options[:not_queriable]== true
|
416
|
+
end
|
417
|
+
|
418
|
+
def self.undefine_attribute(key)
|
419
|
+
return nil if not [String, Symbol].include?(key.class)
|
420
|
+
|
421
|
+
aCaller = caller
|
422
|
+
aCaller.pop
|
423
|
+
|
424
|
+
raise Lorj::PrcError.new(), "%s: No Object defined. Missing define_obj?" % [ self.class], aCaller if @@Context[:oCurrentObj].nil?
|
425
|
+
|
426
|
+
sCloudObj = @@Context[:oCurrentObj]
|
427
|
+
oKeyPath = KeyPath.new(key)
|
428
|
+
|
429
|
+
Lorj::rhSet(@@meta_obj, nil, sCloudObj, :returns, oKeyPath.sFullPath)
|
430
|
+
@@Context[:oCurrentKey] = oKeyPath
|
431
|
+
Lorj::debug(4, "%s: Undefining attribute mapping '%s'" % [sCloudObj, oKeyPath.sFullPath])
|
432
|
+
|
433
|
+
self.query_mapping(key, nil)
|
434
|
+
end
|
435
|
+
|
436
|
+
# Defines/update CloudData parameters
|
437
|
+
def self.define_data(sData, hMeta)
|
438
|
+
return nil if not sData or not hMeta
|
439
|
+
return nil if not [String, Symbol].include?(sData.class)
|
440
|
+
return nil if hMeta.class != Hash
|
441
|
+
|
442
|
+
aCaller = caller
|
443
|
+
aCaller.pop
|
444
|
+
|
445
|
+
sData = sData.to_sym if sData.class == String
|
446
|
+
raise Lorj::PrcError.new(), "%s: Config data '%s' unknown" % [self.class, sData], aCaller if not Lorj::Default.meta_exist?(sData)
|
447
|
+
|
448
|
+
@@Context[:oCurrentData] = sData
|
449
|
+
|
450
|
+
section = Lorj::Default.get_meta_section(sData)
|
451
|
+
section = :runtime if section.nil?
|
452
|
+
|
453
|
+
if Lorj::rhExist?(@@meta_data, section, sData) == 2
|
454
|
+
Lorj::rhGet(@@meta_data, section, sData).merge!(hMeta)
|
455
|
+
else
|
456
|
+
Lorj::rhSet(@@meta_data, hMeta, section, sData)
|
457
|
+
end
|
458
|
+
|
459
|
+
end
|
460
|
+
|
461
|
+
def self.data_value_mapping(value, map)
|
462
|
+
return nil if not [String, Symbol].include?(value.class)
|
463
|
+
return nil if not [NilClass, Symbol, String].include?(map.class)
|
464
|
+
|
465
|
+
aCaller = caller
|
466
|
+
aCaller.pop
|
467
|
+
sData = @@Context[:oCurrentData]
|
468
|
+
raise Lorj::PrcError.new, "Config data context not set. at least, you need to call define_data before." if sData.nil?
|
469
|
+
|
470
|
+
section = Lorj::Default.get_meta_section(sData)
|
471
|
+
section = :runtime if section.nil?
|
472
|
+
|
473
|
+
Lorj.debug(2, "%s/%s: Define config data value mapping: '%s' => '%s'" % [section, sData, value, map])
|
474
|
+
Lorj::rhSet(@@meta_data, map, section, sData, :value_mapping, :controller, value)
|
475
|
+
Lorj::rhSet(@@meta_data, value, section, sData, :value_mapping, :process, map)
|
476
|
+
end
|
477
|
+
|
478
|
+
def self.provides(aObjType)
|
479
|
+
@aObjType = aObjType
|
480
|
+
end
|
481
|
+
|
482
|
+
def self.defined?(objType)
|
483
|
+
@aObjType.include?(objType)
|
484
|
+
end
|
485
|
+
|
486
|
+
# Internal BaseDefinition function
|
487
|
+
|
488
|
+
def self.predefine_data_value(data, hOptions)
|
489
|
+
return nil if self.class != BaseDefinition # Refuse to run if not a BaseDefinition call
|
490
|
+
return nil if not [String, Symbol].include?(value.class)
|
491
|
+
return nil if not [NilClass, Symbol, String].include?(map.class)
|
492
|
+
|
493
|
+
aCaller = caller
|
494
|
+
aCaller.pop
|
495
|
+
|
496
|
+
oKeyPath = @@Context[:oCurrentKey]
|
497
|
+
|
498
|
+
value = {data => {:options => hOptions} }
|
499
|
+
|
500
|
+
Lorj::rhSet(@@predefine_data_value, value, oKeyPath.sFullPath, :values)
|
501
|
+
end
|
502
|
+
|
503
|
+
|
504
|
+
end
|
505
|
+
end
|