lorj 0.2.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +46 -0
  4. data/Gemfile +15 -15
  5. data/README.md +22 -17
  6. data/Rakefile +12 -2
  7. data/bin/cloud_test.rb +13 -65
  8. data/example/students_1/process/students.rb +39 -0
  9. data/example/students_1/students.rb +22 -5
  10. data/example/students_2/process/students.rb +48 -0
  11. data/example/students_2/students.rb +39 -16
  12. data/example/students_3/controller/yaml_students.rb +50 -43
  13. data/example/students_3/controller/yaml_students_controller.rb +100 -87
  14. data/example/students_3/process/students.rb +161 -97
  15. data/example/students_3/students.rb +85 -56
  16. data/example/yaml_students/students.rb +40 -40
  17. data/example/yaml_students/yaml_students.rb +103 -90
  18. data/lib/core/core.rb +356 -696
  19. data/lib/core/core_controller.rb +227 -0
  20. data/lib/core/core_internal.rb +339 -0
  21. data/lib/core/core_model.rb +328 -0
  22. data/lib/core/core_object_data.rb +330 -0
  23. data/lib/core/core_object_params.rb +230 -0
  24. data/lib/core/core_process.rb +391 -0
  25. data/lib/core/core_process_setup.rb +353 -0
  26. data/lib/core/core_setup_ask.rb +241 -0
  27. data/lib/core/core_setup_encrypt.rb +146 -0
  28. data/lib/core/core_setup_init.rb +229 -0
  29. data/lib/core/core_setup_list.rb +160 -0
  30. data/lib/core/definition.rb +647 -469
  31. data/lib/core/definition_internal.rb +264 -308
  32. data/lib/core/lorj_basecontroller.rb +95 -0
  33. data/lib/core/lorj_basedefinition.rb +307 -0
  34. data/lib/core/lorj_baseprocess.rb +265 -0
  35. data/lib/core/lorj_data.rb +583 -0
  36. data/lib/core/lorj_keypath.rb +119 -0
  37. data/lib/core_process/cloud/process/common.rb +63 -0
  38. data/lib/core_process/cloud/process/connection.rb +93 -0
  39. data/lib/core_process/cloud/process/external_network.rb +94 -0
  40. data/lib/core_process/cloud/process/flavor.rb +99 -0
  41. data/lib/core_process/cloud/process/images.rb +87 -0
  42. data/lib/core_process/cloud/process/internet_network.rb +34 -0
  43. data/lib/core_process/cloud/process/internet_server.rb +30 -0
  44. data/lib/core_process/cloud/process/keypairs.rb +276 -0
  45. data/lib/core_process/cloud/process/network.rb +108 -0
  46. data/lib/core_process/cloud/process/public_ip.rb +100 -0
  47. data/lib/core_process/cloud/process/router.rb +260 -0
  48. data/lib/core_process/cloud/process/rules.rb +120 -0
  49. data/lib/core_process/cloud/process/security_groups.rb +121 -0
  50. data/lib/core_process/cloud/process/server.rb +127 -0
  51. data/lib/core_process/cloud/process/server_log.rb +35 -0
  52. data/lib/core_process/cloud/process/subnetwork.rb +108 -0
  53. data/lib/core_process/cloud_process.rb +30 -0
  54. data/lib/logging.rb +298 -0
  55. data/lib/lorj/version.rb +18 -1
  56. data/lib/lorj.rb +58 -18
  57. data/lib/lorj_account.rb +556 -0
  58. data/lib/lorj_config.rb +468 -0
  59. data/lib/lorj_defaults.rb +278 -0
  60. data/lib/prc.rb +136 -104
  61. data/lib/prc_base_config.rb +285 -0
  62. data/lib/prc_core_config.rb +878 -0
  63. data/lib/prc_section_config.rb +57 -0
  64. data/lib/providers/hpcloud/compute.rb +81 -93
  65. data/lib/providers/hpcloud/hpcloud.rb +462 -0
  66. data/lib/providers/hpcloud/network.rb +96 -98
  67. data/lib/providers/hpcloud/security_groups.rb +41 -40
  68. data/lib/providers/mock/mock.rb +144 -0
  69. data/lib/providers/openstack/openstack.rb +45 -0
  70. data/lib/providers/templates/compute.rb +21 -23
  71. data/lib/providers/templates/mycloud.rb +72 -0
  72. data/lib/providers/templates/network.rb +11 -12
  73. data/lib/rh.rb +339 -0
  74. data/lorj-spec/defaults.yaml +4 -0
  75. data/lorj.gemspec +6 -0
  76. data/spec/00_lorj_log_spec.rb +53 -0
  77. data/spec/01_hash_rh_spec.rb +243 -0
  78. data/spec/02_prc_base_config_spec.rb +216 -0
  79. data/spec/04_prc_core_config_spec.rb +83 -0
  80. data/spec/11_lorj_config_spec.rb +263 -0
  81. data/spec/12_lorj_account_spec.rb +181 -0
  82. metadata +76 -28
  83. data/Gemfile.lock +0 -37
  84. data/example/students_1/process/Students.rb +0 -20
  85. data/example/students_2/process/Students.rb +0 -27
  86. data/example/students_4/controller/yaml_students.rb +0 -82
  87. data/example/students_4/controller/yaml_students_controller.rb +0 -141
  88. data/example/students_4/process/students.rb +0 -112
  89. data/example/students_4/students.rb +0 -103
  90. data/lib/core/lorj-basecontroller.rb +0 -90
  91. data/lib/core/lorj-basedefinition.rb +0 -1139
  92. data/lib/core/lorj-baseprocess.rb +0 -236
  93. data/lib/core/lorj-data.rb +0 -567
  94. data/lib/core/lorj-keypath.rb +0 -115
  95. data/lib/core_process/CloudProcess.rb +0 -337
  96. data/lib/core_process/global_process.rb +0 -502
  97. data/lib/core_process/network_process.rb +0 -605
  98. data/lib/prc-account.rb +0 -339
  99. data/lib/prc-config.rb +0 -1030
  100. data/lib/prc-logging.rb +0 -261
  101. data/lib/providers/hpcloud/Hpcloud.rb +0 -426
  102. data/lib/providers/mock/Mock.rb +0 -141
  103. data/lib/providers/openstack/Openstack.rb +0 -47
  104. data/lib/providers/templates/core.rb +0 -61
  105. data/spec/forj-account_spec.rb +0 -75
  106. data/spec/forj-config_spec.rb +0 -196
@@ -14,81 +14,88 @@
14
14
  # See the License for the specific language governing permissions and
15
15
  # limitations under the License.
16
16
 
17
-
18
17
  # This class describes how to process some actions, and will do everything prior
19
18
  # this task to make it to work.
20
19
 
21
-
22
20
  # declare yaml student API to the controller
23
21
  cur_path = File.dirname(__FILE__)
24
- api_file = File.expand_path(File.join(cur_path, "..", "..", "yaml_students", 'yaml_students.rb'))
22
+ api_file = File.expand_path(File.join(cur_path, '..', '..',
23
+ 'yaml_students', 'yaml_students.rb'))
25
24
  require api_file
26
25
 
27
26
  # The controller is a combination of 2 elements:
28
27
  # - Controller class
29
28
  # Code which will interfere with the external API.
30
29
  #
31
- # The file name must respect the name of the class. 1st letter already capitalized and letter after _ is capitalized.
30
+ # The file name must respect the name of the class. 1st letter already
31
+ # capitalized and letter after _ is capitalized.
32
32
  # file: my_code.rb => needs to create MyCodeController class
33
33
  #
34
34
  # - Definition class
35
35
  # This class declare any kind of mapping or additional fields to consider.
36
- # Additionnal fields are unknow by the process. So, those fields will needs to be setup before.
36
+ # Additionnal fields are unknow by the process. So, those fields will needs
37
+ # to be setup before.
37
38
  #
38
39
  # file name convention is identical than controller class.
39
40
  # file: my_code.rb => needs to create MyCode class
40
41
 
41
- controller_file = File.expand_path(File.join(cur_path,'yaml_students_controller.rb'))
42
+ controller_file = File.expand_path(File.join(cur_path,
43
+ 'yaml_students_controller.rb'))
42
44
  require controller_file # Load controller mapping
43
45
 
44
46
  # Declare
45
- # - additional objects and their specific process (:connection using basic predefined :controller_create process)
47
+ # - additional objects and their specific process (:connection using basic
48
+ # predefined :controller_create process)
46
49
  # - data_mapping :
47
50
  # :connection_string => :file_name
48
51
  # :course => :training
49
52
  #
50
- # If some data has been added by the controller, the main and process, won't take care and the framework will fails.
53
+ # If some data has been added by the controller, the main and process,
54
+ # won't take care and the framework will fails.
51
55
  # To eliminate this errors, there is 2 cases:
52
56
  # - detect this change in the process or the main.
53
- # - set it up, using lorj setup function, if the data is declared askable by the controller.
54
- # The controller can define how the setup have to ask values, and even can get data
55
- # from itself.
56
-
57
+ # - set it up, using lorj setup function, if the data is declared askable by
58
+ # the controller.
59
+ # The controller can define how the setup have to ask values, and even can get
60
+ # data from itself.
57
61
  class YamlStudents
62
+ # This is a new object which is known by the controller only.
63
+ # Used to open the yaml file. Generically, I named it :connection.
64
+ # But this can be any name you want. Only the controller will deal with it.
65
+ define_obj(:connection,
66
+ # Nothing complex to do. So, simply call the controller create.
67
+ :create_e => :controller_create
68
+ )
58
69
 
59
- # This is a new object which is known by the controller only.
60
- # Used to open the yaml file. Generically, I named it :connection.
61
- # But this can be any name you want. Only the controller will deal with it.
62
- define_obj(:connection,{
63
- :create_e => :controller_create # Nothing complex to do. So, simply call the controller create.
64
- })
65
-
66
- obj_needs :data, :connection_string, :mapping => :file_name
67
- undefine_attribute :id # Do not return any predefined ID
68
- undefine_attribute :name # Do not return any predefined NAME
70
+ obj_needs :data, :connection_string, :mapping => :file_name
71
+ undefine_attribute :id # Do not return any predefined ID
72
+ undefine_attribute :name # Do not return any predefined NAME
69
73
 
70
- # The student model have to be expanded.
71
- define_obj(:student)
72
- # It requires to create a connection to the data, ie opening the yaml file.
73
- # So, before working with the :student object, the controller requires a connection
74
- # This connection will be loaded in the memory and provided to the controller
75
- # when needed.
76
- # obj_needs :CloudObject update the :student object to requires a connection before.
77
- obj_needs :CloudObject, :connection
74
+ # The student model have to be expanded.
75
+ define_obj(:student)
76
+ # It requires to create a connection to the data, ie opening the yaml file.
77
+ # So, before working with the :student object, the controller requires a
78
+ # connection
79
+ # This connection will be loaded in the memory and provided to the controller
80
+ # when needed.
81
+ # obj_needs :CloudObject update the :student object to requires a connection
82
+ # before.
83
+ obj_needs :CloudObject, :connection
78
84
 
79
- # To simplify controller wrapper, we use hdata built by lorj, and passed to the API
80
- # This hdata is a hash containing mapped data, thanks to set_hdata.
81
- set_hdata :first_name
82
- set_hdata :last_name
83
- # Instead of 'course', the yaml API uses 'training'
84
- set_hdata :course, :mapping => :training
85
+ # To simplify controller wrapper, we use hdata built by lorj, and passed to
86
+ # the API
87
+ # This hdata is a hash containing mapped data, thanks to def_hdata.
88
+ def_hdata :first_name
89
+ def_hdata :last_name
90
+ # Instead of 'course', the yaml API uses 'training'
91
+ def_hdata :course, :mapping => :training
85
92
 
86
- get_attr_mapping :course, :training
87
- # instead of 'student_name', the yaml API uses 'name'
88
- get_attr_mapping :student_name, :name
93
+ def_attr_mapping :course, :training
94
+ # instead of 'student_name', the yaml API uses 'name'
95
+ def_attr_mapping :student_name, :name
89
96
 
90
- # This controller will know how to manage a student file with those data.
91
- # But note that the file can have a lot of more data than what the process
92
- # usually manage. It is up to you to increase your process to manage more data.
93
- # Then each controller may need to define mapping fields.
97
+ # This controller will know how to manage a student file with those data.
98
+ # But note that the file can have a lot of more data than what the process
99
+ # usually manage. It is up to you to increase your process to manage more data
100
+ # Then each controller may need to define mapping fields.
94
101
  end
@@ -14,110 +14,123 @@
14
14
  # See the License for the specific language governing permissions and
15
15
  # limitations under the License.
16
16
 
17
-
18
17
  # This class describes how to process some actions, and will do everything prior
19
18
  # this task to make it to work.
20
19
 
21
20
  # This Mock controller keep the data in memory in hash/Array data.
22
21
 
23
22
  # declare yaml student API to the controller
24
- cur_file = File.expand_path(File.join(File.dirname(File.dirname(__FILE__)), "..", "yaml_students", 'yaml_students.rb'))
25
- require cur_file
23
+ yaml_students_file = File.expand_path(
24
+ File.join(
25
+ File.dirname(__FILE__),
26
+ '..', '..', 'yaml_students', 'yaml_students.rb'))
27
+ require yaml_students_file
26
28
 
27
29
  # The controller is a combination of 2 elements:
28
30
  # - Controller class
29
31
  # Code which will interfere with the external API.
30
32
  #
31
- # The file name must respect the name of the class. 1st letter already capitalized and letter after _ is capitalized.
33
+ # The file name must respect the name of the class. 1st letter already
34
+ # capitalized and letter after _ is capitalized.
32
35
  # file: my_code.rb => needs to create MyCodeController class
33
36
  #
34
37
  # - Definition class
35
38
  # This class declare any kind of mapping or additional fields to consider.
36
- # Additionnal fields are unknow by the process. So, those fields will needs to be setup before.
39
+ # Additionnal fields are unknow by the process. So, those fields will needs
40
+ # to be setup before.
37
41
  #
38
42
  # file name convention is identical than controller class.
39
43
  # file: my_code.rb => needs to create MyCode class
40
-
41
44
  class YamlStudentsController
42
- def initialize()
43
- @@valid_attributes = [:name, :first_name, :last_name, :id, :status, :training]
44
- end
45
-
46
- def create(sObjectType, hParams)
47
- case sObjectType
48
- when :connection
49
- required?(hParams, :hdata, :file_name)
50
- YamlSchool.new(hParams[:hdata, :file_name])
51
- when :student
52
- required?(hParams, :connection)
53
- required?(hParams, :student_name)
54
-
55
- hParams[:connection].create_student(hParams[:student_name], hParams[:hdata])
56
- else
57
- Error "'%s' is not a valid object for 'create'" % sObjectType
58
- end
59
- end
60
-
61
- # This function return a collection which have to provide:
62
- # functions: [], length, each
63
- # Used by network process.
64
- def query(sObjectType, sQuery, hParams)
65
- case sObjectType
66
- when :student
67
- required?(hParams, :connection)
68
-
69
- hParams[:connection].query_student(sQuery)
70
- else
71
- Error "'%s' is not a valid object for 'create'" % sObjectType
72
- end
73
-
74
- end
75
-
76
- def delete(sObjectType, hParams)
77
- case sObjectType
78
- when :student
79
- required?(hParams, :connection)
80
-
81
- hParams[:connection].delete_student(hParams[sObjectType][:id])
82
- else
83
- Error "'%s' is not a valid object for 'create'" % sObjectType
84
- end
85
- end
86
-
87
- def get_attr(oControlerObject, key)
88
- # This controller function read the data and
89
- # extract the information requested by the framework.
90
- # Those data will be mapped to the process data model.
91
- # The key is an array, to get data from a level tree.
92
- # [data_l1, data_l2, data_l3] => should retrieve data from structure like data[ data_l2[ data_l3 ] ]
93
- begin
94
- attributes = oControlerObject
95
- raise "get_attr: attribute '%s' is unknown in '%s'. Valid one are : '%s'" % [key[0], oControlerObject.class, @@valid_attributes ] unless @@valid_attributes.include?(key[0])
96
- Lorj::rhGet(attributes, key)
97
- rescue => e
98
- Error "get_attr: Unable to map '%s'. %s" % [key, e.message]
99
- end
100
- end
101
-
102
- def set_attr(oControlerObject, key, value)
103
- begin
104
- attributes = oControlerObject
105
- raise "set_attr: attribute '%s' is unknown in '%s'. Valid one are : '%s'" % [key[0], oControlerObject.class, @@valid_attributes ] unless @@valid_attributes.include?(key[0])
106
- Lorj::rhSet(attributes, value, key)
107
- rescue => e
108
- Error "set_attr: Unable to map '%s' on '%s'" % [key, sObjectType]
109
- end
110
- end
111
-
112
- def update(sObjectType, oObject, hParams)
113
- case sObjectType
114
- when :student
115
- required?(hParams, :connection)
116
-
117
- hParams[:connection].update_student(oObject)
118
- else
119
- Error "'%s' is not a valid object for 'create'" % sObjectType
120
- end
121
- end
122
-
45
+ # controller wrapper
46
+ # rubocop: disable Metrics/MethodLength
47
+ def create(sObjectType, hParams)
48
+ case sObjectType
49
+ when :connection
50
+ required?(hParams, :hdata, :file_name)
51
+ YamlSchool.new(hParams[:hdata, :file_name])
52
+ when :student
53
+ required?(hParams, :connection)
54
+ required?(hParams, :student_name)
55
+
56
+ hParams[:connection].create_student(hParams[:student_name],
57
+ hParams[:hdata])
58
+ else
59
+ Error format("'%s' is not a valid object for 'create'", sObjectType)
60
+ end
61
+ end
62
+ # rubocop: enable Metrics/MethodLength
63
+
64
+ # This function return a collection which have to provide:
65
+ # functions: [], length, each
66
+ # Used by network process.
67
+ def query(sObjectType, sQuery, hParams)
68
+ case sObjectType
69
+ when :student
70
+ required?(hParams, :connection)
71
+
72
+ hParams[:connection].query_student(sQuery)
73
+ else
74
+ Error format("'%s' is not a valid object for 'create'", sObjectType)
75
+ end
76
+ end
77
+
78
+ def delete(sObjectType, hParams)
79
+ case sObjectType
80
+ when :student
81
+ required?(hParams, :connection)
82
+
83
+ hParams[:connection].delete_student(hParams[sObjectType][:id])
84
+ else
85
+ Error format("'%s' is not a valid object for 'create'", sObjectType)
86
+ end
87
+ end
88
+
89
+ def get_attr(oControlerObject, key)
90
+ # This controller function read the data and
91
+ # extract the information requested by the framework.
92
+ # Those data will be mapped to the process data model.
93
+ # The key is an array, to get data from a level tree.
94
+ # [data_l1, data_l2, data_l3] => should retrieve data from structure like
95
+ # data[ data_l2[ data_l3 ] ]
96
+ attributes = oControlerObject
97
+
98
+ fail format("get_attr: attribute '%s' is unknown in '%s'. "\
99
+ "Valid one are : '%s'",
100
+ key[0],
101
+ oControlerObject.class,
102
+ valid_attributes) unless valid_attributes.include?(key[0])
103
+ attributes.rh_get(key)
104
+ rescue => e
105
+ Error format("get_attr: Unable to map '%s'. %s", key, e.message)
106
+ end
107
+
108
+ def set_attr(oControlerObject, key, value)
109
+ attributes = oControlerObject
110
+ fail format("set_attr: attribute '%s' is unknown in '%s'. "\
111
+ "Valid one are : '%s'",
112
+ key[0],
113
+ oControlerObject.class,
114
+ valid_attributes) unless valid_attributes.include?(key[0])
115
+ attributes.rh_set(value, key)
116
+ rescue
117
+ Error format("set_attr: Unable to map '%s' on '%s'", key, sObjectType)
118
+ end
119
+
120
+ def update(sObjectType, oObject, hParams)
121
+ case sObjectType
122
+ when :student
123
+ required?(hParams, :connection)
124
+
125
+ hParams[:connection].update_student(oObject)
126
+ else
127
+ Error format("'%s' is not a valid object for 'create'", sObjectType)
128
+ end
129
+ end
130
+
131
+ private
132
+
133
+ def valid_attributes
134
+ [:name, :first_name, :last_name, :id, :status, :training]
135
+ end
123
136
  end
@@ -16,103 +16,167 @@
16
16
 
17
17
  # Students process - Define specific handlers
18
18
  class StudentsProcess
19
- def create_student(sObjectType, hParams)
20
- PrcLib::state ("Running creation process for object '%s' = '%s'" % [sObjectType, hParams[:student_name] ])
21
-
22
- # config object is a reference to runtime/config data.
23
- oList = Query(sObjectType, {:student_name => hParams[:student_name]})
24
- case oList.length
25
- when 0
26
- oObject = controller_create(sObjectType)
27
- raise "Student '%s' not created." % hParams[:student_name] if oObject.nil?
28
- PrcLib::info ("'%s': '%s' created with id %s" % [sObjectType, hParams[:student_name], oObject[:id]])
29
- when 1
30
- oObject = oList[0]
31
- PrcLib::info ("'%s': '%s' loaded with id %s" % [sObjectType, hParams[:student_name], oObject[:id]])
32
- else
33
- oObject = oList[0]
34
- PrcLib::warning("More than one student named '%s' is found: %s records. Selecting the first one and removing duplicates." % [hParams[:student_name], oList.length])
35
- iCount = 0
36
- oList[1..-1].each { | elem |
37
- register(elem)
38
- iCount += controller_delete(sObjectType)
39
- }
40
- PrcLib::info ("'%s': %s duplicated '%s' removed. First loaded with id %s" % [sObjectType, iCount, hParams[:student_name], oObject[:id]])
41
- end
42
- oObject
43
- end
44
-
45
- # The following handler is inactive.
46
- # It provides a simple print-out code.
47
- # If you want to activate it:
48
- # * uncomment query_student function
49
- # * update the :student data model
50
- # on query_e, replace controller_query by query_student
51
-
52
- # def query_student(sObjectType, sQuery, hParams)
53
- # PrcLib::state ("Running query process for object '%s' with query '%s'" % [sObjectType, sQuery])
54
- #
55
- # oObjects = controller_query(sObjectType, sQuery)
56
- # raise "Query error." if oObjects.nil?
57
- #
58
- # PrcLib::info ("'%s': Queried. %s records found." % [sObjectType, oObjects.length])
59
- # oObjects
60
- # end
61
-
62
- # This handler is inactive.
63
- # It provides a simple print-out code.
64
- # If you want to activate it:
65
- # * uncomment get_student function
66
- # * update the :student data model
67
- # on get_e, replace controller_get by get_student
68
-
69
- # def delete_student(sObjectType, hParams)
70
- # controller_delete(:student)
71
- # PrcLib::info ("'%s:%s' student removed" % [hParams[:student, :id], hParams[:student, :name]])
72
- # end
19
+ # create_student process handler to get a student.
20
+ #
21
+ # * If not found, create it.
22
+ # * If multiple found, remove duplicates
23
+ # * otherwise return the one found.
24
+ # rubocop:disable Metrics/MethodLength
25
+ def create_student(sObjectType, hParams)
26
+ PrcLib.state(format("Running creation process for object '%s' = '%s'",
27
+ sObjectType, hParams[:student_name]))
28
+
29
+ list = process_query(sObjectType, :student_name => hParams[:student_name])
30
+ case list.length
31
+ when 0
32
+ create_new_student(hParams[:student_name])
33
+ when 1
34
+ found_one_student(list[0], hParams[:student_name])
35
+ else
36
+ found_multiple_students(list, hParams[:student_name])
37
+ end
38
+ end
39
+ # rubocop:enable Metrics/MethodLength
40
+
41
+ private
42
+
43
+ # Create a single new student
44
+ def create_new_student(student_name)
45
+ object = controller_create(:student)
46
+ fail format("Student '%s' not created.", student_name) if object.nil?
47
+
48
+ PrcLib.info(format("'student': '%s' created with id %s",
49
+ student_name,
50
+ object[:id]))
51
+ object
52
+ end
53
+
54
+ # Identified 1 student
55
+ def found_one_student(object, student_name)
56
+ PrcLib.info(format("'student': '%s' loaded with id %s",
57
+ student_name, object[:id]))
58
+ object
59
+ end
60
+
61
+ # Identified multiple identical students
62
+ # It will remove duplicated.
63
+ def found_multiple_students(list, student_name)
64
+ object = list[0]
65
+ PrcLib.warning(format("More than one student named '%s' is found: %s "\
66
+ 'records. Selecting the first one and removing '\
67
+ 'duplicates.',
68
+ student_name, list.length))
69
+ remove_multiple_students(list[1..-1], student_name)
70
+ object
71
+ end
72
+
73
+ # Remove list of identical students
74
+ def remove_multiple_students(list, student_name)
75
+ return false unless list.is_a?(Array)
76
+ return false if list.length == 0
77
+
78
+ count = 0
79
+ list.each { | elem | count += remove_student_object(elem) }
80
+ PrcLib.info(format("'student': %s duplicated '%s' removed. "\
81
+ 'First loaded with id %s',
82
+ count, student_name, object[:id]))
83
+ end
84
+
85
+ def remove_student_object(object)
86
+ register(object)
87
+ controller_delete(:student)
88
+ end
89
+
90
+ # The following handler is inactive.
91
+ # It provides a simple print-out code.
92
+ # If you want to activate it:
93
+ # * uncomment query_student function
94
+ # * update the :student data model
95
+ # on query_e, replace controller_query by query_student
96
+
97
+ # def query_student(sObjectType, sQuery, hParams)
98
+ # PrcLib::state (format("Running query process for object '%s' "\
99
+ # "with query '%s'",
100
+ # sObjectType,
101
+ # sQuery))
102
+ #
103
+ # objects = controller_query(sObjectType, sQuery)
104
+ # raise "Query error." if objects.nil?
105
+ #
106
+ # PrcLib::info (format("'%s': Queried. %s records found.",
107
+ # sObjectType,
108
+ # objects.length))
109
+ # objects
110
+ # end
111
+
112
+ # This handler is inactive.
113
+ # It provides a simple print-out code.
114
+ # If you want to activate it:
115
+ # * uncomment get_student function
116
+ # * update the :student data model
117
+ # on get_e, replace controller_get by get_student
118
+
119
+ # def delete_student(sObjectType, hParams)
120
+ # controller_delete(:student)
121
+ # PrcLib::info (format("'%s:%s' student removed",
122
+ # hParams[:student, :id],
123
+ # hParams[:student, :name]))
124
+ # end
73
125
  end
74
126
 
75
- # Declaring your data model and handlers.
76
- # Process Handlers functions have to be declared before, as lorj check their existence during data model definition.
77
-
78
- class Lorj::BaseDefinition
79
-
80
- # We need to define the student object data model and process handlers to use.
81
- # Process handlers must manipulate data defined here.
82
- #
83
- # The controller can redefine object for it needs, but should NEVER impact the main process.
84
- # The controller can add specific process to deal with internal controller objects.
85
- # But this should never influence the original process model.
86
-
87
- # Use define_obj, to declare the new object managed by lorj with process handlers.
88
- define_obj(:student,
89
- {
90
- :create_e => :create_student, # The function to call in the class Students
91
- :query_e => :controller_query, # We use predefined call to the controller query
92
- :delete_e => :controller_delete # We use predefined call to the controller delete
93
- })
94
-
95
- # obj_needs is used to declare parameters to pass to handlers.
96
- # :for indicates those parameters to be passed to create_e handler only.
97
- # Those data (or objects) will be collected and passed to the process handler as hParams.
98
-
99
- obj_needs :data, :student_name, { :for => [:create_e] }
100
-
101
- # By default, all data are required.
102
- # You can set it as optional. Your process will need to deal with this optional data.
103
- obj_needs_optional
104
- obj_needs :data, :first_name, { :for => [:create_e] }
105
- obj_needs :data, :last_name, { :for => [:create_e] }
106
- obj_needs :data, :course # Note that in this model, the training is renamed as course.
107
- # the controller will need to map it to 'training'.
108
-
109
- # def_attribute defines the data model.
110
- # The process will be able to access those data
111
- def_attribute :course
112
- def_attribute :student_name
113
- def_attribute :first_name
114
- def_attribute :last_name
115
- def_attribute :status
116
-
117
- undefine_attribute :name
127
+ module Lorj
128
+ # Declaring your data model and handlers.
129
+ # Process Handlers functions have to be declared before, as lorj check their
130
+ # existence during data model definition.
131
+ class BaseDefinition
132
+ # We need to define the student object data model and process handlers to
133
+ # use.
134
+ # Process handlers must manipulate data defined here.
135
+ #
136
+ # The controller can redefine object for it needs, but should NEVER impact
137
+ # the main process.
138
+ # The controller can add specific process to deal with internal controller
139
+ # objects.
140
+ # But this should never influence the original process model.
141
+
142
+ # Use define_obj, to declare the new object managed by lorj with process
143
+ # handlers.
144
+
145
+ define_obj(:student,
146
+ # The function to call in the class Students
147
+ :create_e => :create_student,
148
+ # We use predefined call to the controller query
149
+ :query_e => :controller_query,
150
+ # We use predefined call to the controller delete
151
+ :delete_e => :controller_delete
152
+ )
153
+
154
+ # obj_needs is used to declare parameters to pass to handlers.
155
+ # :for indicates those parameters to be passed to create_e handler only.
156
+ # Those data (or objects) will be collected and passed to the process
157
+ # handler as hParams.
158
+
159
+ obj_needs :data, :student_name, :for => [:create_e]
160
+
161
+ # By default, all data are required.
162
+ # You can set it as optional. Your process will need to deal with this
163
+ # optional data.
164
+ obj_needs_optional
165
+ obj_needs :data, :first_name, :for => [:create_e]
166
+ obj_needs :data, :last_name, :for => [:create_e]
167
+ obj_needs :data, :course
168
+ # Note that in this model, the training is renamed as course.
169
+
170
+ # the controller will need to map it to 'training'.
171
+
172
+ # def_attribute defines the data model.
173
+ # The process will be able to access those data
174
+ def_attribute :course
175
+ def_attribute :student_name
176
+ def_attribute :first_name
177
+ def_attribute :last_name
178
+ def_attribute :status
179
+
180
+ undefine_attribute :name
181
+ end
118
182
  end