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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +46 -0
- data/Gemfile +15 -15
- data/README.md +22 -17
- data/Rakefile +12 -2
- data/bin/cloud_test.rb +13 -65
- data/example/students_1/process/students.rb +39 -0
- data/example/students_1/students.rb +22 -5
- data/example/students_2/process/students.rb +48 -0
- data/example/students_2/students.rb +39 -16
- data/example/students_3/controller/yaml_students.rb +50 -43
- data/example/students_3/controller/yaml_students_controller.rb +100 -87
- data/example/students_3/process/students.rb +161 -97
- data/example/students_3/students.rb +85 -56
- data/example/yaml_students/students.rb +40 -40
- data/example/yaml_students/yaml_students.rb +103 -90
- data/lib/core/core.rb +356 -696
- data/lib/core/core_controller.rb +227 -0
- data/lib/core/core_internal.rb +339 -0
- data/lib/core/core_model.rb +328 -0
- data/lib/core/core_object_data.rb +330 -0
- data/lib/core/core_object_params.rb +230 -0
- data/lib/core/core_process.rb +391 -0
- data/lib/core/core_process_setup.rb +353 -0
- data/lib/core/core_setup_ask.rb +241 -0
- data/lib/core/core_setup_encrypt.rb +146 -0
- data/lib/core/core_setup_init.rb +229 -0
- data/lib/core/core_setup_list.rb +160 -0
- data/lib/core/definition.rb +647 -469
- data/lib/core/definition_internal.rb +264 -308
- data/lib/core/lorj_basecontroller.rb +95 -0
- data/lib/core/lorj_basedefinition.rb +307 -0
- data/lib/core/lorj_baseprocess.rb +265 -0
- data/lib/core/lorj_data.rb +583 -0
- data/lib/core/lorj_keypath.rb +119 -0
- data/lib/core_process/cloud/process/common.rb +63 -0
- data/lib/core_process/cloud/process/connection.rb +93 -0
- data/lib/core_process/cloud/process/external_network.rb +94 -0
- data/lib/core_process/cloud/process/flavor.rb +99 -0
- data/lib/core_process/cloud/process/images.rb +87 -0
- data/lib/core_process/cloud/process/internet_network.rb +34 -0
- data/lib/core_process/cloud/process/internet_server.rb +30 -0
- data/lib/core_process/cloud/process/keypairs.rb +276 -0
- data/lib/core_process/cloud/process/network.rb +108 -0
- data/lib/core_process/cloud/process/public_ip.rb +100 -0
- data/lib/core_process/cloud/process/router.rb +260 -0
- data/lib/core_process/cloud/process/rules.rb +120 -0
- data/lib/core_process/cloud/process/security_groups.rb +121 -0
- data/lib/core_process/cloud/process/server.rb +127 -0
- data/lib/core_process/cloud/process/server_log.rb +35 -0
- data/lib/core_process/cloud/process/subnetwork.rb +108 -0
- data/lib/core_process/cloud_process.rb +30 -0
- data/lib/logging.rb +298 -0
- data/lib/lorj/version.rb +18 -1
- data/lib/lorj.rb +58 -18
- data/lib/lorj_account.rb +556 -0
- data/lib/lorj_config.rb +468 -0
- data/lib/lorj_defaults.rb +278 -0
- data/lib/prc.rb +136 -104
- data/lib/prc_base_config.rb +285 -0
- data/lib/prc_core_config.rb +878 -0
- data/lib/prc_section_config.rb +57 -0
- data/lib/providers/hpcloud/compute.rb +81 -93
- data/lib/providers/hpcloud/hpcloud.rb +462 -0
- data/lib/providers/hpcloud/network.rb +96 -98
- data/lib/providers/hpcloud/security_groups.rb +41 -40
- data/lib/providers/mock/mock.rb +144 -0
- data/lib/providers/openstack/openstack.rb +45 -0
- data/lib/providers/templates/compute.rb +21 -23
- data/lib/providers/templates/mycloud.rb +72 -0
- data/lib/providers/templates/network.rb +11 -12
- data/lib/rh.rb +339 -0
- data/lorj-spec/defaults.yaml +4 -0
- data/lorj.gemspec +6 -0
- data/spec/00_lorj_log_spec.rb +53 -0
- data/spec/01_hash_rh_spec.rb +243 -0
- data/spec/02_prc_base_config_spec.rb +216 -0
- data/spec/04_prc_core_config_spec.rb +83 -0
- data/spec/11_lorj_config_spec.rb +263 -0
- data/spec/12_lorj_account_spec.rb +181 -0
- metadata +76 -28
- data/Gemfile.lock +0 -37
- data/example/students_1/process/Students.rb +0 -20
- data/example/students_2/process/Students.rb +0 -27
- data/example/students_4/controller/yaml_students.rb +0 -82
- data/example/students_4/controller/yaml_students_controller.rb +0 -141
- data/example/students_4/process/students.rb +0 -112
- data/example/students_4/students.rb +0 -103
- data/lib/core/lorj-basecontroller.rb +0 -90
- data/lib/core/lorj-basedefinition.rb +0 -1139
- data/lib/core/lorj-baseprocess.rb +0 -236
- data/lib/core/lorj-data.rb +0 -567
- data/lib/core/lorj-keypath.rb +0 -115
- data/lib/core_process/CloudProcess.rb +0 -337
- data/lib/core_process/global_process.rb +0 -502
- data/lib/core_process/network_process.rb +0 -605
- data/lib/prc-account.rb +0 -339
- data/lib/prc-config.rb +0 -1030
- data/lib/prc-logging.rb +0 -261
- data/lib/providers/hpcloud/Hpcloud.rb +0 -426
- data/lib/providers/mock/Mock.rb +0 -141
- data/lib/providers/openstack/Openstack.rb +0 -47
- data/lib/providers/templates/core.rb +0 -61
- data/spec/forj-account_spec.rb +0 -75
- data/spec/forj-config_spec.rb +0 -196
|
@@ -1,6 +1,27 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
|
-
|
|
3
|
-
|
|
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['LORJ_DEV']
|
|
21
|
+
require 'byebug'
|
|
22
|
+
lib_path = File.expand_path(File.join(app_path, '..', '..', 'lib'))
|
|
23
|
+
$LOAD_PATH << lib_path
|
|
24
|
+
end
|
|
4
25
|
require 'lorj'
|
|
5
26
|
require 'ansi'
|
|
6
27
|
|
|
@@ -9,85 +30,93 @@ require 'ansi'
|
|
|
9
30
|
# This object is used to provide configuration data to lorj
|
|
10
31
|
|
|
11
32
|
# The config search is:
|
|
12
|
-
# 1- Application defaults (defaults.yaml) - Not defined by default. update the
|
|
33
|
+
# 1- Application defaults (defaults.yaml) - Not defined by default. update the
|
|
34
|
+
# following line and create defaults.yaml
|
|
13
35
|
# PrcLib.app_defaults = $APP_PATH
|
|
14
|
-
# 2- Local defaults (~/.<Application Name>/config.yaml) - <Application Name> is
|
|
36
|
+
# 2- Local defaults (~/.<Application Name>/config.yaml) - <Application Name> is
|
|
37
|
+
# 'Lorj' by default. Can be updated with following line.
|
|
15
38
|
# PrcLib.app_name = 'myapp'
|
|
16
|
-
# 3 - runtime. Those variables are set, with
|
|
39
|
+
# 3 - runtime. Those variables are set, with config[key] = value
|
|
17
40
|
|
|
18
|
-
|
|
41
|
+
config = Lorj::Config.new # Use Simple Config Object
|
|
19
42
|
|
|
20
43
|
# You can use an account object, which add an extra account level
|
|
21
44
|
# between runtime and config.yaml/app default
|
|
22
|
-
#
|
|
23
|
-
|
|
45
|
+
# config = Lorj::Account.new('MyAccount') #
|
|
24
46
|
|
|
25
|
-
# If you want to see what is happening in the framework, uncomment
|
|
26
|
-
#
|
|
27
|
-
|
|
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.
|
|
28
51
|
|
|
29
52
|
# Initialize the framework
|
|
30
|
-
|
|
53
|
+
processes = [File.join(app_path, 'process', 'students.rb')]
|
|
31
54
|
|
|
32
|
-
|
|
33
|
-
|
|
55
|
+
# ~ student_core = Lorj::Core.new( config, processes, :mock)
|
|
56
|
+
student_core = Lorj::Core.new(config,
|
|
57
|
+
processes,
|
|
58
|
+
File.join(app_path,
|
|
59
|
+
'controller',
|
|
60
|
+
'yaml_students.rb'))
|
|
34
61
|
|
|
35
|
-
|
|
62
|
+
student_core.create(:connection, :connection_string => '/tmp/students.yaml')
|
|
36
63
|
|
|
37
|
-
puts ANSI.bold(
|
|
64
|
+
puts ANSI.bold('Create 1st student:')
|
|
38
65
|
|
|
39
66
|
# Set the student name to use
|
|
40
|
-
# There is different way to set them...
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
67
|
+
# There is different way to set them...
|
|
68
|
+
# Those lines do the same using config object. Choose what you want.
|
|
69
|
+
config.set(:first_name, 'Robert')
|
|
70
|
+
config[:last_name] = 'Redford'
|
|
71
|
+
config[:student_name] = 'Robert Redford'
|
|
72
|
+
config[:course] = 'Art Comedy'
|
|
45
73
|
|
|
46
74
|
# Ask the framework to create the object student 'Robert Redford'
|
|
47
|
-
|
|
75
|
+
student_core.create(:student)
|
|
48
76
|
|
|
49
|
-
puts ANSI.bold(
|
|
77
|
+
puts ANSI.bold('Create 2nd student:')
|
|
50
78
|
# We can set runtime configuration instantly from the Create call
|
|
51
79
|
# The following line :
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
#
|
|
59
|
-
#
|
|
60
|
-
#
|
|
61
|
-
|
|
62
|
-
puts ANSI.bold(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
80
|
+
student_core.create(:student,
|
|
81
|
+
:student_name => 'Anthony Hopkins',
|
|
82
|
+
:first_name => 'Anthony',
|
|
83
|
+
:last_name => 'Hopkins',
|
|
84
|
+
:course => 'Art Drama'
|
|
85
|
+
)
|
|
86
|
+
# config[:student_name] = "Anthony Hopkins"
|
|
87
|
+
# config[:course] = "Art Drama"
|
|
88
|
+
# student_core.Create(:student)
|
|
89
|
+
|
|
90
|
+
puts ANSI.bold('Create 3rd student:')
|
|
91
|
+
student_core.create(:student,
|
|
92
|
+
:student_name => 'Marilyn Monroe',
|
|
93
|
+
:first_name => 'Marilyn',
|
|
94
|
+
:last_name => 'Monroe',
|
|
95
|
+
:course => 'Art Drama'
|
|
96
|
+
)
|
|
69
97
|
# replaced the following :
|
|
70
|
-
#
|
|
71
|
-
#
|
|
98
|
+
# config[:student_name] = "Anthony Hopkins"
|
|
99
|
+
# student_core.Create(:student)
|
|
72
100
|
|
|
73
|
-
puts ANSI.bold(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
101
|
+
puts ANSI.bold('Create mistake')
|
|
102
|
+
student = student_core.create(:student,
|
|
103
|
+
:student_name => 'Anthony Mistake',
|
|
104
|
+
:first_name => 'Anthony',
|
|
105
|
+
:last_name => 'Mistake',
|
|
106
|
+
:course => 'what ever you want!!!'
|
|
107
|
+
)
|
|
80
108
|
|
|
81
|
-
puts "Student created '%s'"
|
|
109
|
+
puts format("Student created '%s'", student[:attrs])
|
|
82
110
|
|
|
83
111
|
# Because the last student was the mistake one, we can directly delete it.
|
|
84
112
|
# Usually, we use get instead.
|
|
85
|
-
puts ANSI.bold(
|
|
86
|
-
|
|
87
|
-
puts
|
|
113
|
+
puts ANSI.bold('Remove mistake')
|
|
114
|
+
student_core.delete(:student)
|
|
115
|
+
puts format('Wrong student to remove: %s = %s',
|
|
116
|
+
student[:id], student[:student_name])
|
|
88
117
|
|
|
89
118
|
puts ANSI.bold("List of students for 'Art Drama':")
|
|
90
|
-
puts
|
|
119
|
+
puts student_core.query(:student, :course => 'Art Drama').to_a
|
|
91
120
|
|
|
92
|
-
puts ANSI.bold(
|
|
93
|
-
puts
|
|
121
|
+
puts ANSI.bold('Deleted students:')
|
|
122
|
+
puts student_core.query(:student, :status => :removed).to_a
|
|
@@ -19,60 +19,60 @@
|
|
|
19
19
|
require 'rubygems'
|
|
20
20
|
require 'ansi'
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
app_path = File.expand_path(File.dirname(__FILE__))
|
|
23
23
|
|
|
24
|
-
require File.join(
|
|
24
|
+
require File.join(app_path, 'yaml_students.rb')
|
|
25
25
|
|
|
26
26
|
school = YamlSchool.new('/tmp/students.yaml')
|
|
27
27
|
|
|
28
|
-
puts ANSI.bold(
|
|
29
|
-
if school.query_student(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
28
|
+
puts ANSI.bold('Create 1st student:')
|
|
29
|
+
if school.query_student(:name => 'Robert Redford').length == 0
|
|
30
|
+
school.create_student('Robert Redford',
|
|
31
|
+
:first_name => 'Robert',
|
|
32
|
+
:last_name => 'Redford',
|
|
33
|
+
:training => 'Art Comedy'
|
|
34
|
+
)
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
-
puts ANSI.bold(
|
|
38
|
-
if school.query_student(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
37
|
+
puts ANSI.bold('Create 2nd student:')
|
|
38
|
+
if school.query_student(:name => 'Anthony Hopkins').length == 0
|
|
39
|
+
school.create_student('Anthony Hopkins',
|
|
40
|
+
:first_name => 'Anthony',
|
|
41
|
+
:last_name => 'Hopkins',
|
|
42
|
+
:training => 'Art Drama'
|
|
43
|
+
)
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
-
puts ANSI.bold(
|
|
47
|
-
if school.query_student(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
46
|
+
puts ANSI.bold('Create 3rd student:')
|
|
47
|
+
if school.query_student(:name => 'Marilyn Monroe').length == 0
|
|
48
|
+
school.create_student('Marilyn Monroe',
|
|
49
|
+
:first_name => 'Marilyn',
|
|
50
|
+
:last_name => 'Mistake',
|
|
51
|
+
:training => 'Art Drama'
|
|
52
|
+
)
|
|
53
53
|
end
|
|
54
54
|
|
|
55
|
-
puts ANSI.bold(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
55
|
+
puts ANSI.bold('Create mistake')
|
|
56
|
+
student = school.create_student('Anthony Mistake',
|
|
57
|
+
:first_name => 'Anthony',
|
|
58
|
+
:last_name => 'Mistake',
|
|
59
|
+
:training => 'what ever you want!!!'
|
|
60
|
+
)
|
|
61
61
|
|
|
62
|
-
puts "Student created: '%s'"
|
|
62
|
+
puts format("Student created: '%s'", student)
|
|
63
63
|
|
|
64
|
-
puts ANSI.bold(
|
|
65
|
-
result = school.query_student(
|
|
64
|
+
puts ANSI.bold('Remove mistake')
|
|
65
|
+
result = school.query_student(:name => 'Anthony Mistake')
|
|
66
66
|
if result.length > 0
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
result.each do | a_student |
|
|
68
|
+
puts format('Wrong student to remove: %s = %s',
|
|
69
|
+
a_student[:id], a_student[:name])
|
|
70
|
+
school.delete_student(a_student[:id])
|
|
71
|
+
end
|
|
71
72
|
end
|
|
72
73
|
|
|
73
|
-
|
|
74
74
|
puts ANSI.bold("List of students for 'Art Drama':")
|
|
75
|
-
puts school.query_student(
|
|
75
|
+
puts school.query_student(:training => 'Art Drama')
|
|
76
76
|
|
|
77
|
-
puts ANSI.bold(
|
|
78
|
-
puts school.query_student(
|
|
77
|
+
puts ANSI.bold('Deleted students:')
|
|
78
|
+
puts school.query_student(:status => :removed)
|
|
@@ -14,102 +14,115 @@
|
|
|
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
|
require 'yaml'
|
|
22
21
|
|
|
22
|
+
# Simple School class saving data in a yaml file.
|
|
23
23
|
class YamlSchool
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
end
|
|
46
|
-
rescue => e
|
|
47
|
-
Lorj.error("%s\n%s" % [e.message, e.backtrace.join("\n")])
|
|
48
|
-
return false
|
|
49
|
-
end
|
|
50
|
-
true
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def create_student(name, fields)
|
|
54
|
-
|
|
55
|
-
if fields[ :first_name].nil? or fields[ :last_name].nil?
|
|
56
|
-
puts "YAML API: Unable to create a student. :first_name and :last_name required."
|
|
57
|
-
return nil
|
|
24
|
+
attr_accessor :file
|
|
25
|
+
attr_accessor :data
|
|
26
|
+
|
|
27
|
+
def initialize(file)
|
|
28
|
+
@data = { :students => [] }
|
|
29
|
+
@file = file
|
|
30
|
+
load_data
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def load_data
|
|
34
|
+
return false unless File.exist?(@file)
|
|
35
|
+
|
|
36
|
+
@data = YAML.load_file(@file)
|
|
37
|
+
@data = { :students => [] } unless @data
|
|
38
|
+
@data[:students] = [] unless @data.key?(:students)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def save_data
|
|
42
|
+
begin
|
|
43
|
+
File.open(@file, 'w') do |out|
|
|
44
|
+
YAML.dump(@data, out)
|
|
58
45
|
end
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
46
|
+
rescue => e
|
|
47
|
+
Lorj.error(format("%s\n%s", e.message, e.backtrace.join("\n")))
|
|
48
|
+
return false
|
|
49
|
+
end
|
|
50
|
+
true
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def create_student(name, fields)
|
|
54
|
+
if fields[:first_name].nil? || fields[:last_name].nil?
|
|
55
|
+
puts 'YAML API: Unable to create a student. '\
|
|
56
|
+
':first_name and :last_name required.'
|
|
57
|
+
return nil
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
result = create_data(name, fields)
|
|
61
|
+
|
|
62
|
+
save_data
|
|
63
|
+
result
|
|
64
|
+
end
|
|
65
|
+
|
|
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
|
+
|
|
80
|
+
def delete_student(sId)
|
|
81
|
+
return false unless File.exist?(file)
|
|
82
|
+
|
|
83
|
+
@data[:students].each do | value |
|
|
84
|
+
next unless value[:id] == sId
|
|
85
|
+
|
|
86
|
+
@data[:students][sId][:status] = :removed
|
|
87
|
+
save_data
|
|
88
|
+
return 1
|
|
89
|
+
end
|
|
90
|
+
0
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def query_student(hQuery)
|
|
94
|
+
result = []
|
|
95
|
+
|
|
96
|
+
@data[:students].each do | hValue |
|
|
97
|
+
elem = hValue
|
|
98
|
+
hQuery.each do | query_key, query_value |
|
|
99
|
+
elem = nil if not_in_query?(hQuery, hValue, query_key, query_value)
|
|
111
100
|
end
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
101
|
+
result << elem if elem
|
|
102
|
+
end
|
|
103
|
+
result
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# check query field and data value.
|
|
107
|
+
# Return true if the query do not match the current data
|
|
108
|
+
def not_in_query?(hQuery, hValue, query_key, query_value)
|
|
109
|
+
return true unless valid_status?(hQuery, hValue)
|
|
110
|
+
return true unless hValue.key?(query_key)
|
|
111
|
+
return true if hValue[query_key] != query_value
|
|
112
|
+
false
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# check if status field is queried. if not consider status != :active.
|
|
116
|
+
# return true if status
|
|
117
|
+
def valid_status?(hQuery, hValue)
|
|
118
|
+
return false if hValue.key?(:status) && hValue[:status] != :active &&
|
|
119
|
+
!hQuery.key?(:status)
|
|
120
|
+
true
|
|
121
|
+
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
|
|
115
128
|
end
|