lorj 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/README.md +39 -579
  4. data/Rakefile +7 -0
  5. data/example/students_1/student_v1.md +115 -0
  6. data/example/students_1/students.rb +8 -2
  7. data/example/students_2/process/students.rb +5 -5
  8. data/example/students_2/student_v2.md +90 -0
  9. data/example/students_2/students.rb +6 -6
  10. data/example/students_3/controller/yaml_students.rb +23 -73
  11. data/example/students_3/controller/yaml_students_code.rb +106 -0
  12. data/example/students_3/controller/yaml_students_def.rb +69 -0
  13. data/example/students_3/process/students.rb +23 -157
  14. data/example/students_3/student_v3.md +283 -0
  15. data/example/students_3/students.rb +26 -83
  16. data/example/students_4/controller/yaml_students.rb +51 -0
  17. data/example/students_4/controller/yaml_students_code.rb +109 -0
  18. data/example/students_4/controller/yaml_students_def.rb +72 -0
  19. data/example/students_4/process/students/code/students.rb +103 -0
  20. data/example/students_4/process/students/definition/students.rb +60 -0
  21. data/example/students_4/process/students.rb +29 -0
  22. data/example/students_4/student_v4.md +191 -0
  23. data/example/students_4/students.rb +65 -0
  24. data/example/students_5/controller/yaml_students.rb +106 -0
  25. data/example/{students_3 → students_5}/controller/yaml_students_controller.rb +5 -3
  26. data/example/students_5/process/students.rb +182 -0
  27. data/example/students_5/student_v5.md +382 -0
  28. data/example/students_5/students.rb +119 -0
  29. data/example/yaml_students/students.rb +1 -1
  30. data/example/yaml_students/yaml_students.rb +102 -23
  31. data/lib/concept.md +3 -3
  32. data/lib/core/core.rb +15 -15
  33. data/lib/core/core_controller.rb +49 -24
  34. data/lib/core/core_internal.rb +2 -2
  35. data/lib/core/core_model.rb +13 -7
  36. data/lib/core/core_object_data.rb +18 -18
  37. data/lib/core/core_object_params.rb +75 -34
  38. data/lib/core/core_process.rb +104 -59
  39. data/lib/core/core_process_setup.rb +11 -11
  40. data/lib/core/core_setup_ask.rb +24 -14
  41. data/lib/core/core_setup_encrypt.rb +17 -15
  42. data/lib/core/core_setup_init.rb +19 -15
  43. data/lib/core/core_setup_list.rb +12 -12
  44. data/lib/core/definition.rb +20 -20
  45. data/lib/core/definition_internal.rb +20 -10
  46. data/lib/core/lorj_basecontroller.rb +8 -8
  47. data/lib/core/lorj_basedefinition.rb +47 -126
  48. data/lib/core/lorj_baseprocess.rb +81 -57
  49. data/lib/core/lorj_data.rb +28 -27
  50. data/lib/core/lorj_keypath.rb +1 -1
  51. data/lib/core_process/cloud/process/flavor.rb +3 -2
  52. data/lib/core_process/cloud/process/keypairs.rb +5 -4
  53. data/lib/core_process/cloud/process/network.rb +4 -3
  54. data/lib/core_process/cloud/process/public_ip.rb +3 -2
  55. data/lib/core_process/cloud/process/rules.rb +7 -6
  56. data/lib/core_process/cloud/process/security_groups.rb +1 -1
  57. data/lib/core_process/cloud/process/server.rb +1 -1
  58. data/lib/core_process/cloud/process/server_log.rb +1 -1
  59. data/lib/core_process/cloud/process/subnetwork.rb +4 -1
  60. data/lib/core_process/cloud_process.rb +1 -1
  61. data/lib/logging.rb +41 -48
  62. data/lib/lorj/version.rb +1 -1
  63. data/lib/lorj.rb +7 -0
  64. data/lib/lorj_account.rb +3 -3
  65. data/lib/lorj_config.rb +1 -1
  66. data/lib/lorj_defaults.rb +222 -26
  67. data/lib/overview.md +120 -0
  68. data/lib/prc.rb +97 -24
  69. data/lib/prc_core_config.rb +134 -52
  70. data/lib/providers/hpcloud/compute.rb +3 -3
  71. data/lib/providers/hpcloud/hpcloud.rb +14 -14
  72. data/lib/providers/hpcloud/network.rb +4 -4
  73. data/lib/providers/hpcloud/security_groups.rb +1 -1
  74. data/lib/providers/mock/mock.rb +3 -3
  75. data/lib/providers/openstack/openstack.rb +12 -12
  76. data/lib/providers/templates/compute.rb +6 -6
  77. data/lib/rh.rb +7 -5
  78. data/spec/04_prc_core_config_spec.rb +52 -0
  79. data/spec/11_lorj_config_spec.rb +1 -1
  80. metadata +21 -3
@@ -0,0 +1,119 @@
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
+ app_path = File.dirname(__FILE__)
19
+
20
+ if ENV['BYEBUG']
21
+ require 'byebug'
22
+ lib_path = File.expand_path(File.join(app_path, '..', '..', 'lib'))
23
+ $LOAD_PATH << lib_path
24
+ end
25
+ require 'lorj'
26
+ require 'ansi'
27
+
28
+ # Load global Config
29
+
30
+ # This object is used to provide configuration data to lorj
31
+
32
+ # The config search is:
33
+ # 1- Application defaults (defaults.yaml) - Not defined by default. update the
34
+ # following line and create defaults.yaml
35
+ # PrcLib.app_defaults = $APP_PATH
36
+ # 2- Local defaults (~/.<Application Name>/config.yaml) - <Application Name> is
37
+ # 'Lorj' by default. Can be updated with following line.
38
+ # PrcLib.app_name = 'myapp'
39
+ # 3 - runtime. Those variables are set, with config[key] = value
40
+
41
+ config = Lorj::Config.new # Use Simple Config Object
42
+
43
+ # You can use an account object, which add an extra account level
44
+ # between runtime and config.yaml/app default
45
+ # config = Lorj::Account.new('MyAccount') #
46
+
47
+ # If you want to see what is happening in the framework, uncomment
48
+ # debug settings.
49
+ # PrcLib.level = Logger::DEBUG # Printed out to your console.
50
+ # PrcLib.core_level = 5 # framework debug levels.
51
+
52
+ # Initialize the framework
53
+ processes = [File.join(app_path, 'process', 'students.rb')]
54
+ controller = File.join(app_path, 'controller', 'yaml_students.rb')
55
+
56
+ # ~ student_core = Lorj::Core.new( config, processes, :mock)
57
+ student_core = Lorj::Core.new(config, processes, controller)
58
+
59
+ student_core.create(:connection, :connection_string => '/tmp/students.yaml')
60
+
61
+ puts ANSI.bold('Create 1st student:')
62
+
63
+ # Set the student name to use
64
+ # There is different way to set them...
65
+ # Those lines do the same using config object. Choose what you want.
66
+ config.set(:first_name, 'Robert')
67
+ config[:last_name] = 'Redford'
68
+ config[:student_name] = 'Robert Redford'
69
+ config[:course] = 'Art Comedy'
70
+
71
+ # Ask the framework to create the object student 'Robert Redford'
72
+ student_core.create(:student)
73
+
74
+ puts ANSI.bold('Create 2nd student:')
75
+ # We can set runtime configuration instantly from the Create call
76
+ # The following line :
77
+ student_core.create(:student,
78
+ :student_name => 'Anthony Hopkins',
79
+ :first_name => 'Anthony',
80
+ :last_name => 'Hopkins',
81
+ :course => 'Art Drama'
82
+ )
83
+ # config[:student_name] = "Anthony Hopkins"
84
+ # config[:course] = "Art Drama"
85
+ # student_core.Create(:student)
86
+
87
+ puts ANSI.bold('Create 3rd student:')
88
+ student_core.create(:student,
89
+ :student_name => 'Marilyn Monroe',
90
+ :first_name => 'Marilyn',
91
+ :last_name => 'Monroe',
92
+ :course => 'Art Drama'
93
+ )
94
+ # replaced the following :
95
+ # config[:student_name] = "Anthony Hopkins"
96
+ # student_core.Create(:student)
97
+
98
+ puts ANSI.bold('Create mistake')
99
+ student = student_core.create(:student,
100
+ :student_name => 'Anthony Mistake',
101
+ :first_name => 'Anthony',
102
+ :last_name => 'Mistake',
103
+ :course => 'what ever you want!!!'
104
+ )
105
+
106
+ puts format("Student created '%s'", student[:attrs])
107
+
108
+ # Because the last student was the mistake one, we can directly delete it.
109
+ # Usually, we use get instead.
110
+ puts ANSI.bold('Remove mistake')
111
+ student_core.delete(:student)
112
+ puts format('Wrong student to remove: %s = %s',
113
+ student[:id], student[:student_name])
114
+
115
+ puts ANSI.bold("List of students for 'Art Drama':")
116
+ puts student_core.query(:student, :course => 'Art Drama').to_a
117
+
118
+ puts ANSI.bold('Deleted students:')
119
+ puts student_core.query(:student, :status => :removed).to_a
@@ -64,7 +64,7 @@ puts format("Student created: '%s'", student)
64
64
  puts ANSI.bold('Remove mistake')
65
65
  result = school.query_student(:name => 'Anthony Mistake')
66
66
  if result.length > 0
67
- result.each do | a_student |
67
+ result.each do |a_student|
68
68
  puts format('Wrong student to remove: %s = %s',
69
69
  a_student[:id], a_student[:name])
70
70
  school.delete_student(a_student[:id])
@@ -24,12 +24,18 @@ class YamlSchool
24
24
  attr_accessor :file
25
25
  attr_accessor :data
26
26
 
27
+ # Initiliaze the API with the yaml file loaded.
28
+ #
29
+ # *Args*:
30
+ # - +file+ : File name to load.
27
31
  def initialize(file)
28
32
  @data = { :students => [] }
29
33
  @file = file
30
34
  load_data
31
35
  end
32
36
 
37
+ # Load data from a yaml file. File name is set at class initialization
38
+ # To change the file name, update the file attribute
33
39
  def load_data
34
40
  return false unless File.exist?(@file)
35
41
 
@@ -38,6 +44,8 @@ class YamlSchool
38
44
  @data[:students] = [] unless @data.key?(:students)
39
45
  end
40
46
 
47
+ # Save the data updated in memory.
48
+ # To change the file name, update the file attribute
41
49
  def save_data
42
50
  begin
43
51
  File.open(@file, 'w') do |out|
@@ -50,6 +58,21 @@ class YamlSchool
50
58
  true
51
59
  end
52
60
 
61
+ # create_student is a very basic function to create a new record in
62
+ # the student yaml file.
63
+ # The student is created in memory.
64
+ # To save it in the file, use save_data.
65
+ #
66
+ # *Args*:
67
+ # - +name+ : This is a generic name. It can be a surname as well
68
+ # - +fields+ : Fields is a Hash list of data to add in the student
69
+ # It can be any kind of field name. But at least 2 are required:
70
+ # - :first_name : First name of the student
71
+ # - :last_name : Last name of the student
72
+ #
73
+ # Ex:
74
+ # create_student('rob', :last_name => 'Redford', :first_name => 'Robert',
75
+ # :class_room => 'Art Drama', :comment => 'Is a good student')
53
76
  def create_student(name, fields)
54
77
  if fields[:first_name].nil? || fields[:last_name].nil?
55
78
  puts 'YAML API: Unable to create a student. '\
@@ -63,24 +86,21 @@ class YamlSchool
63
86
  result
64
87
  end
65
88
 
66
- def create_data(name, fields)
67
- result = fields.clone
68
- result[:name] = name
69
- if name.nil?
70
- result[:name] = format('%s %s', result[:first_name], result[:first_name])
71
- end
72
- result[:status] = :active
73
-
74
- @data[:students] << result
75
-
76
- result[:id] = @data[:students].length - 1
77
- result
78
- end
79
-
89
+ # delete_student is a very basic function to delete a record from
90
+ # the student yaml file.
91
+ # The student is deleted in memory.
92
+ # The deletion is simply an update of the :status to :removed
93
+ # To save it in the file, use save_data.
94
+ #
95
+ # *Args*:
96
+ # - id: If the student ID.
97
+ #
98
+ # Ex:
99
+ # delete_student(2)
80
100
  def delete_student(sId)
81
101
  return false unless File.exist?(file)
82
102
 
83
- @data[:students].each do | value |
103
+ @data[:students].each do |value|
84
104
  next unless value[:id] == sId
85
105
 
86
106
  @data[:students][sId][:status] = :removed
@@ -90,12 +110,38 @@ class YamlSchool
90
110
  0
91
111
  end
92
112
 
113
+ # delete_student is a very basic function to delete a record from
114
+ # the student yaml file.
115
+ # The student is deleted in memory.
116
+ # The deletion is simply an update of the :status to :removed
117
+ # To save it in the file, use save_data.
118
+ #
119
+ # *Args*:
120
+ # - query: Hash of fields to use for the query
121
+ # You can query any fields.
122
+ # Standard one are:
123
+ # - :id : Student ID
124
+ # - :name : Student name or surname
125
+ # - :first_name : First name of the student.
126
+ # - :last_name : Last name of the student.
127
+ #
128
+ # *returns*:
129
+ # - Array: List of records matching all fields.
130
+ # The matching feature is basically limited to field equality.
131
+ # if not found, the Array length will equal to 0.
132
+ #
133
+ # Ex:
134
+ # query_student(:id => 2)
135
+ # query_student(:first_name => 'Robert')
136
+ # query_student(:class => 'Art Drama')
93
137
  def query_student(hQuery)
94
138
  result = []
95
139
 
96
- @data[:students].each do | hValue |
140
+ hQuery[:status] = :active unless hQuery.key?(:status)
141
+
142
+ @data[:students].each do |hValue|
97
143
  elem = hValue
98
- hQuery.each do | query_key, query_value |
144
+ hQuery.each do |query_key, query_value|
99
145
  elem = nil if not_in_query?(hQuery, hValue, query_key, query_value)
100
146
  end
101
147
  result << elem if elem
@@ -103,6 +149,45 @@ class YamlSchool
103
149
  result
104
150
  end
105
151
 
152
+ # update_student is a very basic function to update a record of
153
+ # the student yaml file.
154
+ # The student is updated in memory.
155
+ # To save it in the file, use save_data.
156
+ #
157
+ # *Args*:
158
+ # - query: Hash of fields to use for the query
159
+ # You can query any fields.
160
+ # Standard one are:
161
+ # - :id : Student ID
162
+ # - :name : Student name or surname
163
+ # - :first_name : First name of the student.
164
+ # - :last_name : Last name of the student.
165
+ # - :status : :removed if the record is deleted.
166
+ #
167
+ # Ex:
168
+ # query_student(2, :name => 'robby')
169
+ def update_student(id, fields)
170
+ list = query_student(:id => id)
171
+ list[0].merge(fields) if list.length == 1
172
+ save_data
173
+ end
174
+
175
+ private
176
+
177
+ def create_data(name, fields)
178
+ result = fields.clone
179
+ result[:name] = name
180
+ if name.nil?
181
+ result[:name] = format('%s %s', result[:first_name], result[:first_name])
182
+ end
183
+ result[:status] = :active
184
+
185
+ @data[:students] << result
186
+
187
+ result[:id] = @data[:students].length - 1
188
+ result
189
+ end
190
+
106
191
  # check query field and data value.
107
192
  # Return true if the query do not match the current data
108
193
  def not_in_query?(hQuery, hValue, query_key, query_value)
@@ -119,10 +204,4 @@ class YamlSchool
119
204
  !hQuery.key?(:status)
120
205
  true
121
206
  end
122
-
123
- def update_student(_sId, fields)
124
- list = query_student(:id => Id)
125
- list[0].merge(fields) if list.length == 1
126
- save_data
127
- end
128
207
  end
data/lib/concept.md CHANGED
@@ -7,7 +7,7 @@ lorj framework model
7
7
 
8
8
  The framework is built over several pieces:
9
9
 
10
- ![](img/forj-lib-concept.png "concept")
10
+ ![](../../lib/img/forj-lib-concept.png "concept")
11
11
 
12
12
  * Main
13
13
 
@@ -61,7 +61,7 @@ lorj defines 2 different objects to provide configuration data management. But y
61
61
 
62
62
  Short summary about Config `get`, `set` and `save`
63
63
 
64
- ![](img/config_data_access.png)
64
+ ![](../../lib/img/config_data_access.png)
65
65
 
66
66
 
67
67
  * Lorj::Account
@@ -77,7 +77,7 @@ Short summary about Config `get`, `set` and `save`
77
77
 
78
78
  Short summary about Account `get`, `set` and `save`.
79
79
 
80
- ![](img/account_data_access.png)
80
+ ![](../../lib/img/account_data_access.png)
81
81
 
82
82
  ###Application config file : defaults.yaml
83
83
 
data/lib/core/core.rb CHANGED
@@ -52,13 +52,13 @@ module Lorj
52
52
  #
53
53
  # oCloud = Lorj::CloudCore.new(oConfig, 'myhpcloud')
54
54
  # oConfig.set(:server_name,'myservername')
55
- # oCloud.Create(:server)
55
+ # oCloud.create(:server)
56
56
  #
57
57
  # Another basic example (See example directory)
58
58
  #
59
59
  # oConfig = Lorj::Account.new()
60
60
  # oPrc = Lorj::Core.new(oConfig, 'mySqlAccount')
61
- # oCloud.Create(:student, { :student_name => "Robert Redford"})
61
+ # oCloud.create(:student, { :student_name => "Robert Redford"})
62
62
  #
63
63
  # See BaseProcess to check how you can write a process and what kind of
64
64
  # functions are available for your process to be kept controller independant.
@@ -116,7 +116,7 @@ module Lorj
116
116
  # * *Raises* :
117
117
  # No exceptions
118
118
 
119
- def connect(oCloudObj, hConfig = {})
119
+ def connect(oCloudObj, hConfig = nil)
120
120
  return nil if !oCloudObj || !@core_object
121
121
  @core_object.process_create(oCloudObj, hConfig)
122
122
  end
@@ -144,7 +144,7 @@ module Lorj
144
144
  #
145
145
  # * *Raises* :
146
146
  # No exceptions
147
- def create(oCloudObj, hConfig = {})
147
+ def create(oCloudObj, hConfig = nil)
148
148
  return nil if !oCloudObj || !@core_object
149
149
  @core_object.process_create(oCloudObj, hConfig)
150
150
  end
@@ -164,7 +164,7 @@ module Lorj
164
164
  # * *Raises* :
165
165
  # No exceptions
166
166
 
167
- def get_or_create(oCloudObj, hConfig = {})
167
+ def get_or_create(oCloudObj, hConfig = nil)
168
168
  return nil if !oCloudObj || !@core_object
169
169
  @core_object.process_create(oCloudObj, hConfig)
170
170
  end
@@ -186,7 +186,7 @@ module Lorj
186
186
  # * *Raises* :
187
187
  # No exceptions
188
188
 
189
- def delete(oCloudObj, hConfig = {})
189
+ def delete(oCloudObj, hConfig = nil)
190
190
  return nil if !oCloudObj || !@core_object
191
191
 
192
192
  @core_object.process_delete(oCloudObj, hConfig)
@@ -208,7 +208,7 @@ module Lorj
208
208
  # * *Raises* :
209
209
  # No exceptions
210
210
 
211
- def query(oCloudObj, sQuery, hConfig = {})
211
+ def query(oCloudObj, sQuery, hConfig = nil)
212
212
  return nil if !oCloudObj || !@core_object
213
213
 
214
214
  @core_object.process_query(oCloudObj, sQuery, hConfig)
@@ -231,7 +231,7 @@ module Lorj
231
231
  # * *Raises* :
232
232
  # No exceptions
233
233
 
234
- def get(oCloudObj, sId, hConfig = {})
234
+ def get(oCloudObj, sId, hConfig = nil)
235
235
  return nil if !oCloudObj || !@core_object || sId.nil?
236
236
 
237
237
  @core_object.process_get(oCloudObj, sId, hConfig)
@@ -258,7 +258,7 @@ module Lorj
258
258
  # * *Raises* :
259
259
  # No exceptions
260
260
 
261
- def update(oCloudObj, hConfig = {})
261
+ def update(oCloudObj, hConfig = nil)
262
262
  return nil if !oCloudObj || !@core_object
263
263
 
264
264
  @core_object.process_update(oCloudObj, hConfig)
@@ -324,8 +324,8 @@ module Lorj
324
324
  # Load Application processes
325
325
  init_processes(model, the_process_class)
326
326
 
327
- fail Lorj::PrcError.new, 'Lorj::Core: No valid process loaded. '\
328
- 'Aborting.' if model[:process_class].nil?
327
+ PrcLib.runtime_fail 'Lorj::Core: No valid process loaded. '\
328
+ 'Aborting.' if model[:process_class].nil?
329
329
 
330
330
  # Load Controller and Controller processes.
331
331
  init_controller(model, controller_class) if controller_class
@@ -342,11 +342,11 @@ module Lorj
342
342
  def initialize(oConfig, sAccount = nil, aProcesses = [])
343
343
  config_account = init_config(oConfig, sAccount)
344
344
 
345
- process_list = [:CloudProcess]
345
+ process_list = [:cloud_process]
346
346
 
347
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?
348
+ PrcLib.runtime_fail 'Provider_name not set. Unable to create'\
349
+ ' instance CloudCore.' if controller_mod.nil?
350
350
 
351
351
  init_controller_mod(process_list, controller_mod)
352
352
 
@@ -356,7 +356,7 @@ module Lorj
356
356
  private
357
357
 
358
358
  def init_config(oConfig, sAccount)
359
- if !oConfig.is_a?(Lorj::Account)
359
+ if oConfig.is_a?(Lorj::Account)
360
360
  config_account = oConfig
361
361
  else
362
362
  config_account = Lorj::Account.new(oConfig)
@@ -35,12 +35,14 @@ module Lorj
35
35
  # parameters:
36
36
  # - +object_type+: Lorj object type to use for the connection.
37
37
  # - +params+ : Parameters to use for connection.
38
- def controller_connect(sObjectType, params = {})
39
- controller_params = _get_object_params(sObjectType, :create_e, :connect,
40
- true, params)
38
+ def controller_connect(sObjectType, params = nil)
39
+ _add_instant_config(params)
40
+
41
+ controller_params = _get_controller_params(sObjectType,
42
+ :create_e, :connect)
41
43
  controller_obj = @controller.connect(sObjectType, controller_params)
42
44
  data_obj = Lorj::Data.new
43
- data_obj.set(controller_obj, sObjectType) do | sObjType, oObject |
45
+ data_obj.set(controller_obj, sObjectType) do |sObjType, oObject|
44
46
  begin
45
47
  _return_map(sObjType, oObject)
46
48
  rescue => e
@@ -57,14 +59,16 @@ module Lorj
57
59
  # parameters:
58
60
  # - +object_type+: Lorj object type to use for the creation.
59
61
  # - +params+ : Parameters to use for creation.
60
- def controller_create(sObjectType, params = {})
62
+ def controller_create(sObjectType, params = nil)
63
+ _add_instant_config(params)
64
+
61
65
  # The process ask the controller to create the object.
62
66
  # controller_params have to be fully readable by the controller.
63
- controller_params = _get_object_params(sObjectType, :create_e, :create,
64
- true, params)
67
+ controller_params = _get_controller_params(sObjectType,
68
+ :create_e, :create)
65
69
  controller_obj = @controller.create(sObjectType, controller_params)
66
70
  data_obj = Lorj::Data.new
67
- data_obj.set(controller_obj, sObjectType) do | sObjType, oObject |
71
+ data_obj.set(controller_obj, sObjectType) do |sObjType, oObject|
68
72
  begin
69
73
  _return_map(sObjType, oObject)
70
74
  rescue => e
@@ -74,6 +78,8 @@ module Lorj
74
78
  end
75
79
  @object_data.add data_obj
76
80
 
81
+ _remove_instant_config(params)
82
+
77
83
  data_obj
78
84
  end
79
85
 
@@ -86,14 +92,19 @@ module Lorj
86
92
  #
87
93
  # returns:
88
94
  # - The controller must return true to inform about the real deletion
89
- def controller_delete(sObjectType, params = {})
90
- controller_params = _get_object_params(sObjectType, :delete_e, :delete,
91
- true, params)
95
+ def controller_delete(sObjectType, params = nil)
96
+ _add_instant_config(params)
97
+
98
+ controller_params = _get_controller_params(sObjectType,
99
+ :delete_e, :delete)
92
100
  PrcLib.runtime_fail "delete Controller - %s: Object '%s' is not loaded.",
93
101
  @controller.class,
94
102
  key unless controller_params.exist?(sObjectType)
95
103
  state = @controller.delete(sObjectType, controller_params)
96
104
  @object_data.delete(sObjectType) if state
105
+
106
+ _remove_instant_config(params)
107
+
97
108
  state
98
109
  end
99
110
 
@@ -105,13 +116,15 @@ module Lorj
105
116
  #
106
117
  # returns:
107
118
  # - Return a Lorj::Data representing the data retrieved by the controller.
108
- def controller_get(sObjectType, sUniqId, params = {})
109
- controller_params = _get_object_params(sObjectType, :get_e, :get,
110
- true, params)
119
+ def controller_get(sObjectType, sUniqId, params = nil)
120
+ _add_instant_config(params)
121
+
122
+ controller_params = _get_controller_params(sObjectType,
123
+ :get_e, :get)
111
124
 
112
125
  controller_obj = @controller.get(sObjectType, sUniqId, controller_params)
113
126
  data_obj = Lorj::Data.new
114
- data_obj.set(controller_obj, sObjectType) do | sObjType, oObject |
127
+ data_obj.set(controller_obj, sObjectType) do |sObjType, oObject|
115
128
  begin
116
129
  _return_map(sObjType, oObject)
117
130
  rescue => e
@@ -121,6 +134,8 @@ module Lorj
121
134
  end
122
135
  @object_data.add data_obj
123
136
 
137
+ _remove_instant_config(params)
138
+
124
139
  data_obj
125
140
  end
126
141
 
@@ -132,7 +147,9 @@ module Lorj
132
147
  #
133
148
  # returns:
134
149
  # - Returns a Lorj::Data object, containing a list of Lorj::Data element.
135
- def controller_query(sObjectType, hQuery, params = {})
150
+ def controller_query(sObjectType, hQuery, params = nil)
151
+ _add_instant_config(params)
152
+
136
153
  # Check if we can re-use a previous query
137
154
  list = @object_data[:query, sObjectType]
138
155
  unless list.nil?
@@ -143,8 +160,8 @@ module Lorj
143
160
  end
144
161
  end
145
162
 
146
- controller_params = _get_object_params(sObjectType, :query_e, :query,
147
- true, params)
163
+ controller_params = _get_controller_params(sObjectType,
164
+ :query_e, :query)
148
165
  controller_query = _query_map(sObjectType, hQuery)
149
166
 
150
167
  controller_obj = @controller.query(sObjectType, controller_query,
@@ -152,7 +169,7 @@ module Lorj
152
169
 
153
170
  data_obj = Lorj::Data.new :list
154
171
  data_obj.set(controller_obj,
155
- sObjectType, hQuery) do | sObjType, key |
172
+ sObjectType, hQuery) do |sObjType, key|
156
173
  begin
157
174
  _return_map(sObjType, key)
158
175
  rescue => e
@@ -165,6 +182,9 @@ module Lorj
165
182
  sObjectType, data_obj.length)
166
183
 
167
184
  @object_data.add data_obj
185
+
186
+ _remove_instant_config(params)
187
+
168
188
  data_obj
169
189
  end
170
190
 
@@ -176,19 +196,21 @@ module Lorj
176
196
  #
177
197
  # returns:
178
198
  # - The controller must return true to inform about the real deletion
179
- def controller_update(sObjectType, params = {})
199
+ def controller_update(sObjectType, params = NIL)
200
+ _add_instant_config(params)
201
+
180
202
  # Need to detect data updated and update the Controler object with the
181
203
  # controler
182
204
 
183
- controller_params = _get_object_params(sObjectType, :update_e, :update,
184
- true, params)
205
+ controller_params = _get_controller_params(sObjectType,
206
+ :update_e, :update)
185
207
 
186
208
  data_obj = @object_data[sObjectType, :ObjectData]
187
209
  controller_obj = data_obj[:object]
188
210
 
189
211
  is_updated = false
190
212
  attributes = data_obj[:attrs]
191
- attributes.each do |key, value |
213
+ attributes.each do |key, value|
192
214
  attribute_obj = KeyPath.new(key)
193
215
 
194
216
  attribute_map = PrcLib.model.meta_obj.rh_get(sObjectType, :returns,
@@ -213,7 +235,7 @@ module Lorj
213
235
 
214
236
  Lorj.debug(1, '%s.%s - updated.',
215
237
  @process.class, sObjectType) if is_done
216
- data_obj.set(controller_obj, sObjectType) do | sObjType, an_object |
238
+ data_obj.set(controller_obj, sObjectType) do |sObjType, an_object|
217
239
  begin
218
240
  _return_map(sObjType, an_object)
219
241
  rescue => e
@@ -221,6 +243,9 @@ module Lorj
221
243
  @process.class, sObjectType, e.message
222
244
  end
223
245
  end
246
+
247
+ _remove_instant_config(params)
248
+
224
249
  is_done
225
250
  end
226
251
  end
@@ -221,7 +221,7 @@ module Lorj
221
221
  def init_processes(model, processes)
222
222
  process_array = processes_as_array(processes)
223
223
 
224
- process_array.each do | a_process |
224
+ process_array.each do |a_process|
225
225
  a_process = a_process.to_s if a_process.is_a?(Symbol)
226
226
  unless load_process(model, a_process)
227
227
  PrcLib.warning("Process '%s' not properly loaded.", a_process)
@@ -295,7 +295,7 @@ module Lorj
295
295
 
296
296
  match_found = the_process_class.scan(/_[a-z]/)
297
297
  if match_found
298
- match_found.each { | str | the_process_class[str] = str[1].capitalize }
298
+ match_found.each { |str| the_process_class[str] = str[1].capitalize }
299
299
  end
300
300
 
301
301
  the_process_class
@@ -293,16 +293,22 @@ module Lorj
293
293
  end
294
294
 
295
295
  # Object Context identifier (get/set)
296
- # parameters: (Hash)
297
- # - +:object+ : optional. Object to keep in context.
298
- # - +:function_name+ : optional. Symbol. Call function name for error report
296
+ # parameters:
297
+ # - options: Hash.
298
+ # - +:object+ : optional. Object to keep in context.
299
+ # - +:function_name+ : optional. Symbol. Call function name for error
300
+ # report
299
301
  # return:
300
302
  # - string : Object name
301
303
  def object_context(options = nil)
302
- if options.is_a?(Hash) && options.key?(:object)
303
- @context[:oCurrentObj] = options[:object]
304
- needs_optional false
305
- needs_setup false
304
+ if options.is_a?(Hash)
305
+ if options.key?(:object)
306
+ @context[:oCurrentObj] = options[:object]
307
+ needs_optional false
308
+ needs_setup false
309
+ end
310
+ else
311
+ options = {}
306
312
  end
307
313
 
308
314
  msg = ''