lorj 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c3ea57c85015a879c6ae4a17ae32cc568d7c1559
4
- data.tar.gz: 88617061e04fc13f17454c770dc41ad87a19c2b5
3
+ metadata.gz: eeba3dfb1287558282764e42fab9e32628ebbbd3
4
+ data.tar.gz: 27119784fb89ca8911f2cc722f1a2d09454d5e7a
5
5
  SHA512:
6
- metadata.gz: 8d8214f417ae51f763015aa0836d30365ca34b3313c0bafd002cbae137e8a75478261aeb80d9d2d6ccc3575dfc13483501a5fb80aefb11e4ec6d1da2369958d3
7
- data.tar.gz: 4262c71516afea78b39dc03482e972d4465347bec1062d9198648c0dfd7c934b3957c48f46c2b61bcac2e68477433efc9359737143f8b0dfd92962b8a3b1cf67
6
+ metadata.gz: d936b458e2a74c00f165a3b3d41d914aab89602ef250cc08c4ede8fc0f649aba765818f3fe2e1beab5abfe72ac03f9a96e73f86230a38f962313818eb1c5eaa6
7
+ data.tar.gz: ad7e7604d301400b754c1811de06d5711f11563c2e35663cc2bb1f3ce46168772139cdc9979167ca655602f229af954d6bb15cf47beab7754b03bfb3a82a114d
data/.gitignore CHANGED
@@ -12,3 +12,4 @@
12
12
  *.a
13
13
  mkmf.log
14
14
  lorj-rspec.log
15
+ Gemfile.lock
data/.rubocop.yml ADDED
@@ -0,0 +1,46 @@
1
+ # Copyright 2013 Hewlett-Packard Development Company, L.P.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ # use: rubocop --show-cops
16
+ # to validate configuration.
17
+ # rubocop config
18
+ AllCops:
19
+ Include:
20
+ - '**/Rakefile'
21
+ - '**/config.ru'
22
+ Exclude:
23
+ - 'docker/**/*'
24
+ - 'bin/scripts/**/*'
25
+ - 'git/**/*'
26
+ - 'tmp/**/*'
27
+ #Documentation:
28
+ # Enabled: false
29
+ #Metrics/LineLength:
30
+ # Max: 99
31
+ Style/HashSyntax:
32
+ EnforcedStyle: hash_rockets
33
+
34
+ # lets start with 40, but 10 is way to small..
35
+ Metrics/MethodLength:
36
+ Max: 40
37
+ # If Method length is increased, class length need to be extended as well.
38
+ Metrics/ClassLength:
39
+ Max: 150
40
+
41
+ # allow arguments to be longer than 15
42
+ Metrics/AbcSize:
43
+ Max: 40
44
+ # forj-docker binary name gets an exception
45
+ Style/FileName:
46
+ Exclude: ['bin/forj-docker', 'lib/**/forj-docker.rb']
data/Gemfile CHANGED
@@ -3,23 +3,23 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in procontrol.gemspec
4
4
  gemspec
5
5
 
6
- #group(:development, :test) do
6
+ # group(:development, :test) do
7
7
  # gem 'rake'
8
8
  # gem 'debugger'
9
9
  # gem 'byebug'
10
10
  # gem 'rspec', "~> 3.1.0", :require => false
11
- #end
11
+ # end
12
12
 
13
- #gem 'mime-types','1.25.1'
14
- #gem 'excon','0.31.0'
15
- #gem 'json','1.7.5'
16
- #gem 'nokogiri','1.5.11'
17
- #gem 'fog', '1.19.0'
18
- #gem 'git', '>=1.2.7'
19
- #gem 'rainbow'
20
- #gem 'rbx-require-relative', '~> 0.0.7'
21
- #gem 'thor', '>=0.16.0'
22
- #gem 'hpcloud', '~>2.0.9'
23
- #gem 'highline','>=1.6.21'
24
- #gem 'ansi','>=1.4.3'
25
- #gem 'encryptor','>=1.3.0'
13
+ # gem 'mime-types','1.25.1'
14
+ # gem 'excon','0.31.0'
15
+ # gem 'json','1.7.5'
16
+ # gem 'nokogiri','1.5.11'
17
+ # gem 'fog', '1.19.0'
18
+ # gem 'git', '>=1.2.7'
19
+ # gem 'rainbow'
20
+ # gem 'rbx-require-relative', '~> 0.0.7'
21
+ # gem 'thor', '>=0.16.0'
22
+ # gem 'hpcloud', '~>2.0.9'
23
+ # gem 'highline','>=1.6.21'
24
+ # gem 'ansi','>=1.4.3'
25
+ # gem 'encryptor','>=1.3.0'
data/README.md CHANGED
@@ -153,14 +153,14 @@ Currently, this model do nothing except printing out.
153
153
  #####typical output
154
154
 
155
155
  $ example/students_1/students.rb
156
- WARNING: PrcLib.app_defaults is not set. Application defaults won't be loaded.
156
+ WARNING: PrcLib.app_defaults is not set. Application defaults won't be loaded.
157
157
  Running creation process for object 'student' = 'Robert Redford'
158
158
  WARNING: 'create_student' has returned no data for object Lorj::Data 'student'!
159
159
 
160
- There is 2 warnings.
160
+ There is 2 warnings.
161
161
 
162
162
  * **PrcLib.app_defaults** represents the application name. It is used to keep your application configuration data in ~/.{PrcLib.app_defaults}/ directory. Defining this data in your main, will eliminate this warning.
163
- * **create_student** function in your process has returned nothing. while lorj is called to create an object, it assumes to get the object data created. Lorj keep those data in a cache. In this example, **create_student** returned nil, and lorj raise a warning about that.
163
+ * **create_student** function in your process has returned nothing. while lorj is called to create an object, it assumes to get the object data created. Lorj keep those data in a cache. In this example, **create_student** returned nil, and lorj raise a warning about that.
164
164
 
165
165
  ---
166
166
  #### Writing student version 2
@@ -235,7 +235,7 @@ The update your main and add those lines. In the following, we create 3 students
235
235
  #####typical output:
236
236
 
237
237
  $ example/students_2/students.rb
238
- WARNING: PrcLib.app_defaults is not set. Application defaults won't be loaded.
238
+ WARNING: PrcLib.app_defaults is not set. Application defaults won't be loaded.
239
239
  2 students found
240
240
  0: Robert Redford
241
241
  1: Robert Redford
@@ -515,11 +515,14 @@ We need to write the controller part, now. As I said, it is like a wrapper. Let'
515
515
  # extract the information requested by the framework.
516
516
  # Those data will be mapped to the process data model.
517
517
  # The key is an array, to get data from a level tree.
518
- # [data_l1, data_l2, data_l3] => should retrieve data from structure like data[ data_l2[ data_l3 ] ]
518
+ # [data_l1, data_l2, data_l3] => should retrieve data from structure
519
+ # like data[ data_l2 [ data_l3 ] ]
519
520
  begin
520
521
  attributes = oControlerObject
521
- 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])
522
- Lorj::rhGet(attributes, key)
522
+ raise "get_attr: attribute '%s' is unknown in '%s'. Valid one are : '%s'",
523
+ key[0], oControlerObject.class,
524
+ @@valid_attributes unless @@valid_attributes.include?(key[0])
525
+ Lorj::rh_get(attributes, key)
523
526
  rescue => e
524
527
  Error "get_attr: Unable to map '%s'. %s" % [key, e.message]
525
528
  end
@@ -528,8 +531,10 @@ We need to write the controller part, now. As I said, it is like a wrapper. Let'
528
531
  def set_attr(oControlerObject, key, value)
529
532
  begin
530
533
  attributes = oControlerObject
531
- 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])
532
- Lorj::rhSet(attributes, value, key)
534
+ raise "set_attr: attribute '%s' is unknown in '%s'. Valid one are : '%s'",
535
+ key[0], oControlerObject.class,
536
+ @@valid_attributes unless @@valid_attributes.include?(key[0])
537
+ Lorj::rh_set(attributes, value, key)
533
538
  rescue => e
534
539
  Error "set_attr: Unable to map '%s' on '%s'" % [key, sObjectType]
535
540
  end
@@ -575,11 +580,11 @@ And we need to write some mapping stuff to the controller. We have to add this
575
580
  define_obj(:connection,{
576
581
  :create_e => :controller_create # Nothing complex to do. So, simply call the controller create.
577
582
  })
578
-
583
+
579
584
  obj_needs :data, :connection_string, :mapping => :file_name
580
585
  undefine_attribute :id # Do not return any predefined ID
581
586
  undefine_attribute :name # Do not return any predefined NAME
582
-
587
+
583
588
  # The student model have to be expanded.
584
589
  define_obj(:student)
585
590
  # It requires to create a connection to the data, ie opening the yaml file.
@@ -587,18 +592,18 @@ And we need to write some mapping stuff to the controller. We have to add this
587
592
  # This connection will be loaded in the memory and provided to the controller
588
593
  # when needed.
589
594
  obj_needs :CloudObject, :connection
590
-
595
+
591
596
  # To simplify controller wrapper, we use hdata built by lorj, and passed to the API
592
597
  # This hdata is a hash containing mapped data, thanks to set_hdata.
593
598
  set_hdata :first_name
594
599
  set_hdata :last_name
595
600
  # Instead of 'course', the yaml API uses 'training'
596
601
  set_hdata :course, :mapping => :training
597
-
602
+
598
603
  get_attr_mapping :course, :training
599
604
  # instead of 'student_name', the yaml API uses 'name'
600
605
  get_attr_mapping :student_name, :name
601
-
606
+
602
607
  # This controller will know how to manage a student file with those data.
603
608
  # But note that the file can have a lot of more data than what the process
604
609
  # usually manage. It is up to you to increase your process to manage more data.
@@ -609,8 +614,8 @@ And we need to write some mapping stuff to the controller. We have to add this
609
614
  That's it!
610
615
 
611
616
  #####typical output:
612
- $ example/students_3/students.rb
613
- WARNING: PrcLib.app_defaults is not set. Application defaults won't be loaded.
617
+ $ example/students_3/students.rb
618
+ WARNING: PrcLib.app_defaults is not set. Application defaults won't be loaded.
614
619
  Create 1st student:
615
620
  Create 2nd student:
616
621
  Create 3rd student:
@@ -623,7 +628,7 @@ That's it!
623
628
  {:id=>2, :course=>"Art Drama", :student_name=>"Marilyn Monroe", :first_name=>"Marilyn", :last_name=>"Monroe", :status=>:active}
624
629
  Deleted students:
625
630
  {:id=>3, :course=>"what ever you want!!!", :student_name=>"Anthony Mistake", :first_name=>"Anthony", :last_name=>"Mistake", :status=>:removed}
626
-
631
+
627
632
  ## What next?
628
633
 
629
634
  Check the code in the `examples/students_3/`. It provides a little more than is written here.
data/Rakefile CHANGED
@@ -14,11 +14,21 @@
14
14
  # See the License for the specific language governing permissions and
15
15
  # limitations under the License.
16
16
 
17
- require "bundler/gem_tasks"
17
+ require 'bundler/gem_tasks'
18
18
  require 'rspec/core/rake_task'
19
+ require 'rubocop/rake_task'
20
+
21
+ task :default => [:lint, :spec]
19
22
 
20
23
  desc 'Run the specs.'
21
- RSpec::Core::RakeTask.new do |t|
24
+ RSpec::Core::RakeTask.new do |t|
22
25
  t.pattern = 'spec/*_spec.rb'
26
+ t.rspec_opts = '-f doc'
23
27
  end
24
28
 
29
+ desc 'Run RuboCop on the project'
30
+ RuboCop::RakeTask.new(:lint) do |task|
31
+ task.formatters = ['progress']
32
+ task.verbose = true
33
+ task.fail_on_error = true
34
+ end
data/bin/cloud_test.rb CHANGED
@@ -1,81 +1,29 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- #require 'byebug'
3
+ # require 'byebug'
4
4
 
5
- $APP_PATH = File.dirname(__FILE__)
6
- $LIB_PATH = File.expand_path(File.join(File.dirname($APP_PATH),'lib'))
5
+ app_path = File.dirname(__FILE__)
6
+ lib_path = File.expand_path(File.join(File.dirname(app_path), 'lib'))
7
7
 
8
- $LOAD_PATH << $LIB_PATH
8
+ load_path << lib_path
9
9
 
10
- $LOAD_PATH << File.join($LIB_PATH, 'lib-forj', 'lib')
11
-
12
- require 'appinit.rb'
13
-
14
- # Initialize forj paths
15
- AppInit::forj_initialize()
16
-
17
- # Initialize global Log object
18
- $FORJ_LOGGER=LorjLog.new()
19
-
20
- require 'lib-forj.rb'
21
-
22
- Logging.set_level(Logger::DEBUG)
10
+ require 'lorj.rb'
23
11
 
24
12
  # Load global Config
25
- oConfig = ForjConfig.new()
13
+ oconfig = ForjConfig.new
26
14
 
27
- aProcesses = []
15
+ processes = []
28
16
 
29
17
  # Defines how to manage Maestro and forges
30
18
  # create a maestro box. Identify a forge instance, delete it,...
31
- aProcesses << File.join($LIB_PATH, 'forj', 'ForjCore.rb')
19
+ processes << File.join(lib_path, 'forj', 'ForjCore.rb')
32
20
 
33
21
  # Defines how cli will control FORJ features
34
22
  # boot/down/ssh/...
35
- aProcesses << File.join($LIB_PATH, 'forj', 'ForjCli.rb')
36
-
37
- $LIB_FORJ_DEBUG = 3 # verbose
38
-
39
- infra_dir = File.expand_path(oConfig.get(:infra_repo))
40
-
41
- # Ask information if needed.
42
- if not Dir.exist?(File.expand_path(infra_dir))
43
- Logging.warning(<<-END
44
- Your infra workspace directory is missing.
45
-
46
- Forj uses an infra workspace directory to store any kind of data that are private to you.
47
- We provides ways to send those data securily to your new Forge instance, as metadata.
48
- In production case, we suggest you to keep it safe in your SCM preferred database.
49
-
50
- If you already have an existing infra workspace, use 'forj set infra_repo=<PathToYourRepo>' to set it and restart.
51
-
52
- Otherwise, we will build a new one with some predefined data, you can review and update later.
53
- END
54
- )
55
- sAsk = "Do you want to create a new one from Maestro (yes/no)?" % [infra_dir]
56
- bBuildInfra=agree(sAsk)
57
- if not bBuildInfra
58
- puts 'Process aborted on your demand.'
59
- exit 0
60
- end
61
- end
62
-
63
- oCloud = ForjCloud.new(oConfig, 'hpcloud', aProcesses)
64
-
65
- #oConfig.set(:instance_name, "test")
66
- #oCloud.Create(:metadata)
67
- #oCloud.Create(:infra_repository)
68
- #oCloud.Create(:userdata)
69
-
70
-
71
- #oCloud.Setup(:server, 'hpcloud')
72
- #oCloud.Setup(:forge, 'hpcloud')
73
-
74
- #oCloud.Create(:forge)
23
+ processes << File.join(lib_path, 'forj', 'ForjCli.rb')
75
24
 
76
- oConfig.set(:box_name, '183')
77
- oConfig.set(:box, 'maestro')
78
- #oConfig.Create(:server)
79
- oCloud.Create(:ssh)
25
+ ocloud = ForjCloud.new(oconfig, 'hpcloud', processes)
80
26
 
81
- #oCloud.Query(:server, 'maestro')
27
+ oconfig.set(:box_name, '183')
28
+ oconfig.set(:box, 'maestro')
29
+ ocloud.Create(:ssh)
@@ -0,0 +1,39 @@
1
+ # encoding: UTF-8
2
+
3
+ # (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ # Students process
18
+ class StudentsProcess
19
+ def create_student(sObjectType, hParams)
20
+ puts format("Running creation process for object '%s' = '%s'",
21
+ sObjectType, hParams[:student_name])
22
+ # If you prefer to print out to the log system instead:
23
+ # PrcLib::debug(format("Running creation process for object '%s' = '%s'",
24
+ # sObjectType, hParams[:student_name] ))
25
+ end
26
+ end
27
+
28
+ # Declaring your data model and handlers.
29
+ # Rubocop: Disabling Style/ClassAndModuleChildren to avoid un-needed indentation
30
+ class Lorj::BaseDefinition # rubocop:disable Style/ClassAndModuleChildren
31
+ # We need to define the student object and the handler to use while we need
32
+ # to create it.
33
+ define_obj(:student,
34
+ # The function to call in the class Students
35
+ :create_e => :create_student
36
+ )
37
+
38
+ obj_needs :data, :student_name, :for => [:create_e]
39
+ end
@@ -1,16 +1,33 @@
1
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__)
2
19
 
3
- $APP_PATH = File.dirname(__FILE__)
4
20
  require 'lorj'
5
21
 
6
- # If you want to see what is happening in the framework, uncomment debug settings.
22
+ # If you want to see what is happening in the framework, uncomment debug
23
+ # settings.
7
24
  # PrcLib.level = Logger::DEBUG # Printed out to your console.
8
25
  # PrcLib.core_level = 3 # framework debug levels.
9
26
 
10
27
  # Initialize the framework
11
- hProcesses = [ File.join($APP_PATH, 'process', 'Students.rb')]
28
+ processes = [File.join(app_path, 'process', 'students.rb')]
12
29
 
13
- oStudentCore = Lorj::Core.new( nil, hProcesses)
30
+ student_core = Lorj::Core.new(nil, processes)
14
31
 
15
32
  # Ask the framework to create the object student 'Robert Redford'
16
- oStudentCore.Create(:student, :student_name => "Robert Redford")
33
+ student_core.create(:student, :student_name => 'Robert Redford')
@@ -0,0 +1,48 @@
1
+ # encoding: UTF-8
2
+
3
+ # (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ # Students process
18
+ class StudentsProcess
19
+ def create_student(sObjectType, hParams)
20
+ PrcLib.state(format("Running creation process for object '%s' = '%s'",
21
+ sObjectType, hParams[:student_name]))
22
+
23
+ object = controller_create(sObjectType)
24
+ fail format("Student '%s' not created.",
25
+ hParams[:student_name]) if object.nil?
26
+ PrcLib.info(format("'%s': '%s' created with id %s",
27
+ sObjectType, hParams[:student_name], object[:id]))
28
+ object
29
+ end
30
+ end
31
+
32
+ # Declaring your data model and handlers.
33
+ class Lorj::BaseDefinition # rubocop: disable Style/ClassAndModuleChildren
34
+ # We need to define the student object and the handler to use while we need to
35
+ # create it.
36
+ define_obj(:student,
37
+ # The function to call in the class Students
38
+ :create_e => :create_student,
39
+ # We use predefined call to the controller query
40
+ :query_e => :controller_query,
41
+ # We use predefined call to the controller get
42
+ :get_e => :controller_get,
43
+ # We use predefined call to the controller delete
44
+ :delete_e => :controller_delete
45
+ )
46
+
47
+ obj_needs :data, :student_name, :for => [:create_e], :mapping => :name
48
+ end
@@ -1,36 +1,59 @@
1
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['LORJ_DEV']
21
+ require 'byebug'
22
+ lib_path = File.expand_path(File.join(app_path, '..', '..', 'lib'))
23
+ $LOAD_PATH << lib_path
24
+ end
2
25
 
3
- $APP_PATH = File.dirname(__FILE__)
4
26
  require 'lorj'
5
27
 
6
- # If you want to see what is happening in the framework, uncomment debug settings.
7
- # PrcLib.level = Logger::DEBUG # Printed out to your console.
8
- # PrcLib.core_level = 3 # framework debug levels.
28
+ # If you want to see what is happening in the framework, uncomment debug
29
+ # settings.
30
+ PrcLib.level = Logger::DEBUG # Printed out to your console.
31
+ PrcLib.core_level = 3 # framework debug levels.
9
32
 
10
33
  # Initialize the framework
11
- hProcesses = [ File.join($APP_PATH, 'process', 'Students.rb')]
34
+ processes = [File.join(app_path, 'process', 'students.rb')]
12
35
 
13
- oStudentCore = Lorj::Core.new( nil, hProcesses, :mock)
36
+ student_core = Lorj::Core.new(nil, processes, :mock)
14
37
 
15
38
  # Ask the framework to create the object student 'Robert Redford'
16
- oStudentCore.Create(:student, :student_name => "Robert Redford")
39
+ student_core.create(:student, :student_name => 'Robert Redford')
17
40
 
18
41
  # Want to create a duplicated student 'Robert Redford'?
19
- oStudentCore.Create(:student)
42
+ student_core.create(:student)
20
43
  # no problem. The key is the key in the Mock controller array.
21
44
 
22
- oStudentCore.Create(:student, :student_name => "Anthony Hopkins")
45
+ student_core.create(:student, :student_name => 'Anthony Hopkins')
23
46
 
24
47
  # Let's create a third different student.
25
- oStudents = oStudentCore.Query(:student, { :name => "Robert Redford" } )
48
+ students = student_core.query(:student, :name => 'Robert Redford')
26
49
 
27
- puts "%s students found" % oStudents.length
50
+ puts format('%s students found', students.length)
28
51
 
29
- oStudents.each { | oStudent |
30
- puts "%s: %s" % [oStudent[:id], oStudent[:name]]
31
- }
52
+ students.each do | a_student |
53
+ puts format('%s: %s', a_student[:id], a_student[:name])
54
+ end
32
55
 
33
56
  # let's check the get function, who is the ID 2?
34
- oStudent = oStudentCore.Get(:student, 2)
57
+ student = student_core.get(:student, 2)
35
58
 
36
- puts "The student ID 2 is %s" % oStudent[:name]
59
+ puts format('The student ID 2 is %s', student[:name])