apiotics-test 0.1.49

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +260 -0
  4. data/Rakefile +33 -0
  5. data/lib/apiotics.rb +58 -0
  6. data/lib/apiotics/client.rb +20 -0
  7. data/lib/apiotics/configuration.rb +23 -0
  8. data/lib/apiotics/extract.rb +107 -0
  9. data/lib/apiotics/hardware.rb +109 -0
  10. data/lib/apiotics/insert.rb +115 -0
  11. data/lib/apiotics/parse.rb +20 -0
  12. data/lib/apiotics/portal.rb +217 -0
  13. data/lib/apiotics/railtie.rb +14 -0
  14. data/lib/apiotics/server.rb +238 -0
  15. data/lib/apiotics/version.rb +3 -0
  16. data/lib/generators/apiotics/channel/USAGE +10 -0
  17. data/lib/generators/apiotics/channel/channel_generator.rb +35 -0
  18. data/lib/generators/apiotics/channel/templates/apiotics_channel.rb.erb +9 -0
  19. data/lib/generators/apiotics/channel/templates/apiotics_channel_client.coffee.erb +16 -0
  20. data/lib/generators/apiotics/channel/templates/apiotics_channel_initializer.rb.erb +3 -0
  21. data/lib/generators/apiotics/controller/USAGE +8 -0
  22. data/lib/generators/apiotics/controller/controller_generator.rb +25 -0
  23. data/lib/generators/apiotics/controller/templates/apiotics_scaffold.rb.erb +60 -0
  24. data/lib/generators/apiotics/create_model/USAGE +10 -0
  25. data/lib/generators/apiotics/create_model/create_model_generator.rb +76 -0
  26. data/lib/generators/apiotics/create_model/templates/apiotics_logs_model.rb.erb +7 -0
  27. data/lib/generators/apiotics/create_model/templates/apiotics_model.rb.erb +49 -0
  28. data/lib/generators/apiotics/create_model/templates/apiotics_module.rb.erb +14 -0
  29. data/lib/generators/apiotics/create_model/templates/apiotics_module_model.rb.erb +8 -0
  30. data/lib/generators/apiotics/create_model/templates/create_module_model_table.rb.erb +9 -0
  31. data/lib/generators/apiotics/create_table/USAGE +9 -0
  32. data/lib/generators/apiotics/create_table/create_table_generator.rb +62 -0
  33. data/lib/generators/apiotics/create_table/templates/create_logs_table.rb.erb +14 -0
  34. data/lib/generators/apiotics/create_table/templates/create_table.rb.erb +16 -0
  35. data/lib/generators/apiotics/initializer/USAGE +8 -0
  36. data/lib/generators/apiotics/initializer/initializer_generator.rb +29 -0
  37. data/lib/generators/apiotics/initializer/templates/apiotics.rb.erb +10 -0
  38. data/lib/generators/apiotics/initializer/templates/apiotics_module.rb.erb +6 -0
  39. data/lib/generators/apiotics/initializer/templates/apiotics_parents.rb.erb +3 -0
  40. data/lib/generators/apiotics/initializer/templates/apiotics_settings.rb.erb +9 -0
  41. data/lib/generators/apiotics/initializer/templates/apiotics_targets.rb.erb +4 -0
  42. data/lib/generators/apiotics/initializer/templates/setting.rb.erb +3 -0
  43. data/lib/generators/apiotics/install/USAGE +11 -0
  44. data/lib/generators/apiotics/install/install_generator.rb +11 -0
  45. data/lib/generators/apiotics/migration/USAGE +10 -0
  46. data/lib/generators/apiotics/migration/migration_generator.rb +54 -0
  47. data/lib/generators/apiotics/migration/templates/create_logs_table.rb.erb +14 -0
  48. data/lib/generators/apiotics/migration/templates/migrate_table.rb.erb +12 -0
  49. data/lib/generators/apiotics/model/USAGE +11 -0
  50. data/lib/generators/apiotics/model/model_generator.rb +58 -0
  51. data/lib/generators/apiotics/scaffold/scaffold_generator.rb +23 -0
  52. data/lib/generators/apiotics/scaffold/templates/USAGE +0 -0
  53. data/lib/generators/apiotics/script/USAGE +8 -0
  54. data/lib/generators/apiotics/script/script_generator.rb +45 -0
  55. data/lib/generators/apiotics/script/templates/comm_server.rake +19 -0
  56. data/lib/generators/apiotics/script/templates/dev_comm_server.rake +19 -0
  57. data/lib/generators/apiotics/script/templates/dev_server.rb +8 -0
  58. data/lib/generators/apiotics/script/templates/dev_server_control.rb +7 -0
  59. data/lib/generators/apiotics/script/templates/install_firmware.rake +10 -0
  60. data/lib/generators/apiotics/script/templates/publish_script.rake +6 -0
  61. data/lib/generators/apiotics/script/templates/script.rb.erb +12 -0
  62. data/lib/generators/apiotics/script/templates/server.rb +8 -0
  63. data/lib/generators/apiotics/script/templates/server_control.rb +7 -0
  64. data/lib/generators/apiotics/script/templates/test_comm_server.rake +19 -0
  65. data/lib/generators/apiotics/script/templates/test_server.rb +8 -0
  66. data/lib/generators/apiotics/script/templates/test_server_control.rb +7 -0
  67. data/lib/generators/apiotics/view/USAGE +12 -0
  68. data/lib/generators/apiotics/view/templates/default.css.erb +18 -0
  69. data/lib/generators/apiotics/view/templates/edit.html.erb +6 -0
  70. data/lib/generators/apiotics/view/templates/form.html.erb +52 -0
  71. data/lib/generators/apiotics/view/templates/index.html.erb +66 -0
  72. data/lib/generators/apiotics/view/templates/show.html.erb +56 -0
  73. data/lib/generators/apiotics/view/view_generator.rb +26 -0
  74. data/lib/tasks/simbiotes_tasks.rake +4 -0
  75. metadata +256 -0
@@ -0,0 +1,14 @@
1
+ class <%= class_name %>Logs < ActiveRecord::Migration[5.1]
2
+ def change
3
+ create_table :<%= logs_table_name(@k) %> do |t|
4
+ t.<%= @v %> :<%= @k %>
5
+ t.boolean :<%= @k %>_ack
6
+ t.boolean :<%= @k %>_complete
7
+ t.string :<%= @k %>_timestamp
8
+ t.string :<%= @k %>_status
9
+ t.string :<%= @k %>_action
10
+ t.integer :<%= table_name %>_id
11
+ t.timestamps
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ class <%= class_name %> < ActiveRecord::Migration[5.1]
2
+ def change
3
+ <% attributes.each do |k,v| %>
4
+ add_column :<%= table_name %>, :<%= k %>, :<%= v %>
5
+ add_column :<%= table_name %>, :<%= k %>_ack, :boolean
6
+ add_column :<%= table_name %>, :<%= k %>_complete, :boolean
7
+ add_column :<%= table_name %>, :<%= k %>_timestamp, :string
8
+ add_column :<%= table_name %>, :<%= k %>_status, :string
9
+ add_column :<%= table_name %>, :<%= k %>_action, :string
10
+ <% end %>
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ Description:
2
+ Creates a model and associated database table with the attributes specified. If using data from the portal (recommended) Worker should be the name of a worker defined in your Hive, and Model should be the name of a Driver or Script in that Worker.
3
+
4
+ Example:
5
+ rails generate apiotics:model Worker Model attribute:type attribute:type ... attribute:type
6
+
7
+ This will create:
8
+ app/models/worker.rb
9
+ app/models/worker/model.rb
10
+ db/migrate/{datetime_stamp}_create_table.rb
11
+ db/migrate/{datetime_stamp}_create_table_attribute_logs.rb
@@ -0,0 +1,58 @@
1
+ module Apiotics
2
+ class ModelGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+ argument :parent, :type => :string
5
+ argument :name, :type => :string
6
+ argument :attributes, :type => :hash, :required => false
7
+
8
+ def run_generators
9
+ generate "apiotics:create_table", arguments
10
+ if @c == nil
11
+ generate "apiotics:create_model", "#{parent} #{name}"
12
+ else
13
+ generate "apiotics:create_model", thorify
14
+ generate "apiotics:initializer", "true"
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def arguments
21
+ if attributes == nil
22
+ return get_attributes
23
+ else
24
+ return parent.to_s + " " + name.to_s + " " + stringify
25
+ end
26
+ end
27
+
28
+ def stringify
29
+ string = String.new
30
+ attributes.each do |k,v|
31
+ string = string + k + ":" + v + " "
32
+ end
33
+ string
34
+ end
35
+
36
+ def get_attributes
37
+ @c = Apiotics.get_attributes(parent, name)
38
+ if @c[:kind] == "script"
39
+ generate "apiotics:script", "#{parent} #{name}"
40
+ end
41
+ string = String.new
42
+ @c[:attributes].each do |k,v|
43
+ if v[:type] == "enum"
44
+ string = string + k.gsub(" ", "_").downcase + ":" + "integer" + " "
45
+ else
46
+ string = string + k.gsub(" ", "_").downcase + ":" + v[:type] + " "
47
+ end
48
+ end
49
+ return parent.to_s + " " + name.to_s + " " + string
50
+ end
51
+
52
+ def thorify
53
+ string = String.new
54
+ string = parent.to_s + " " + name.to_s + " " + "true"
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,23 @@
1
+ module Apiotics
2
+ class ScaffoldGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+ argument :worker_name, :type => :string
5
+
6
+ def create_scaffold
7
+ @c = Apiotics::Portal.parse_all_interfaces
8
+ generate "apiotics:initializer", "true"
9
+ drivers = @c[worker_name].keys
10
+ drivers.each do |driver|
11
+ generate "apiotics:model", "#{worker_name} #{driver}"
12
+ end
13
+ generate "apiotics:controller", "#{worker_name}"
14
+ end
15
+
16
+ private
17
+
18
+ def date_string
19
+ date_string = DateTime.now.strftime("%Y%m%d%H%M%S")
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Generate a stub script to run on a device
3
+
4
+ Example:
5
+ rails generate apiotics:script Thing
6
+
7
+ This will create:
8
+ lib/scripts/apiotics/thing.rb
@@ -0,0 +1,45 @@
1
+ module Apiotics
2
+ class ScriptGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+ argument :parent, :type => :string, :required => false
5
+ argument :name, :type => :string, :required => false
6
+
7
+ def create_script
8
+ if name != nil
9
+ @c = Apiotics::Portal.get_attributes(parent, name)
10
+ template "script.rb.erb", "lib/scripts/apiotics/#{parent_file_name}/#{file_name}.rb"
11
+ end
12
+ copy_file "server.rb", "lib/scripts/server.rb"
13
+ copy_file "test_server.rb", "lib/scripts/test_server.rb"
14
+ copy_file "dev_server.rb", "lib/scripts/dev_server.rb"
15
+ copy_file "server_control.rb", "lib/scripts/server_control.rb"
16
+ copy_file "test_server_control.rb", "lib/scripts/test_server_control.rb"
17
+ copy_file "dev_server_control.rb", "lib/scripts/dev_server_control.rb"
18
+ copy_file "comm_server.rake", "lib/tasks/comm_server.rake"
19
+ copy_file "test_comm_server.rake", "lib/tasks/test_comm_server.rake"
20
+ copy_file "dev_comm_server.rake", "lib/tasks/dev_comm_server.rake"
21
+ copy_file "publish_script.rake", "lib/tasks/publish_script.rake"
22
+ copy_file "install_firmware.rake", "lib/tasks/install_firmware.rake"
23
+ FileUtils.chmod 0775, "lib/scripts/server_control.rb"
24
+ end
25
+
26
+ private
27
+
28
+ def file_name
29
+ name.underscore
30
+ end
31
+
32
+ def class_name
33
+ name.classify
34
+ end
35
+
36
+ def parent_class_name
37
+ parent.classify
38
+ end
39
+
40
+ def parent_file_name
41
+ parent.underscore
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,19 @@
1
+ namespace :comms do
2
+ desc "Start local communication server"
3
+ task start: :environment do
4
+ system("ruby", "#{Rails.root}/lib/scripts/server_control.rb", "start")
5
+ puts $?
6
+ end
7
+
8
+ desc "Stop local communication server"
9
+ task stop: :environment do
10
+ system("ruby", "#{Rails.root}/lib/scripts/server_control.rb", "stop")
11
+ puts $?
12
+ end
13
+
14
+ desc "Restart local communication server"
15
+ task restart: :environment do
16
+ system("ruby", "#{Rails.root}/lib/scripts/server_control.rb", "restart")
17
+ puts $?
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ namespace :dev_comms do
2
+ desc "Start local communication server"
3
+ task start: :environment do
4
+ system("ruby", "#{Rails.root}/lib/scripts/dev_server_control.rb", "start")
5
+ puts $?
6
+ end
7
+
8
+ desc "Stop local communication server"
9
+ task stop: :environment do
10
+ system("ruby", "#{Rails.root}/lib/scripts/dev_server_control.rb", "stop")
11
+ puts $?
12
+ end
13
+
14
+ desc "Restart local communication server"
15
+ task restart: :environment do
16
+ system("ruby", "#{Rails.root}/lib/scripts/dev_server_control.rb", "restart")
17
+ puts $?
18
+ end
19
+ end
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Load Rails
4
+ ENV['RAILS_ENV'] = ARGV[0] || 'development'
5
+ DIR = File.dirname(__FILE__)
6
+ require DIR + '/../../config/environment'
7
+
8
+ Apiotics::Server.new
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # add the ontop: true option to see the output of the server in the console in which you run rake comms:start
4
+
5
+ require 'daemons'
6
+
7
+ Daemons.run("lib/scripts/dev_server.rb", ontop: false)
@@ -0,0 +1,10 @@
1
+ namespace :firmware do
2
+ desc "Install firmware on devices. Use rake firmware:install {worker_name} to install firmware on a device. Use rake firmware:install {worker_name} {instance_name} to install firmware and set a name for the device."
3
+ task :install, [:worker, :name] => [:environment] do |task, args|
4
+ if args[:name] == nil
5
+ Apiotics::Hardware.openocd(args[:worker], nil)
6
+ else
7
+ Apiotics::Hardware.openocd(args[:worker], args[:name])
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,6 @@
1
+ namespace :script do
2
+ desc "Publish script to the hive."
3
+ task :publish, [:worker, :name] => [:environment] do |task, args|
4
+ Apiotics::Portal.upload_script(args[:worker], args[:name])
5
+ end
6
+ end
@@ -0,0 +1,12 @@
1
+ #######
2
+ # This script will be deployed to your device.
3
+ # The $global variables below represent the values your script will receive/needs to provide to/from its various interfaces and inputs.
4
+ # Your script should change the value of these variables to what they should be, and they will then get passed back.
5
+ # You can also add additional global variables. If you do, these will be passed back to the script along with the
6
+ # interface and input variables the next time the script is invoked. These are useful for keeping state across script
7
+ # invocations.
8
+ <% @c[:attributes].each do |k,v|%>
9
+ $<%= k.gsub(" ","_") %><% end %><% @c[:inputs].each do |k,v|%>
10
+ $<%= "#{k.gsub(" ","_")}_#{v.gsub(" ","_")}" %><% end %>
11
+
12
+ # put your logic here.
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Load Rails
4
+ ENV['RAILS_ENV'] = ARGV[0] || 'production'
5
+ DIR = File.dirname(__FILE__)
6
+ require DIR + '/../../config/environment'
7
+
8
+ Apiotics::Server.new
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # add the ontop: true option to see the output of the server in the console in which you run rake comms:start
4
+
5
+ require 'daemons'
6
+
7
+ Daemons.run('lib/scripts/server.rb', ontop: false)
@@ -0,0 +1,19 @@
1
+ namespace :test_comms do
2
+ desc "Start local communication server"
3
+ task start: :environment do
4
+ system("ruby", "#{Rails.root}/lib/scripts/dev_server_control.rb", "start")
5
+ puts $?
6
+ end
7
+
8
+ desc "Stop local communication server"
9
+ task stop: :environment do
10
+ system("ruby", "#{Rails.root}/lib/scripts/dev_server_control.rb", "stop")
11
+ puts $?
12
+ end
13
+
14
+ desc "Restart local communication server"
15
+ task restart: :environment do
16
+ system("ruby", "#{Rails.root}/lib/scripts/dev_server_control.rb", "restart")
17
+ puts $?
18
+ end
19
+ end
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Load Rails
4
+ ENV['RAILS_ENV'] = ARGV[0] || 'test'
5
+ DIR = File.dirname(__FILE__)
6
+ require DIR + '/../../config/environment'
7
+
8
+ Apiotics::Server.new
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # add the ontop: true option to see the output of the server in the console in which you run rake comms:start
4
+
5
+ require 'daemons'
6
+
7
+ Daemons.run("lib/scripts/test_server.rb", ontop: false)
@@ -0,0 +1,12 @@
1
+ Description:
2
+ Creates a model and associated database table with the attributes specified. If using data from the portal (recommended) Worker should be the name of a worker defined in your Hive, and Model should be the name of a Driver or Script in that Worker.
3
+
4
+ Example:
5
+ rails generate apiotics:view Worker
6
+
7
+ This will create:
8
+ app/views/worker/show.html.erb
9
+ app/views/worker/new.html.erb
10
+ app/views/worker/edit.html.erb
11
+ app/views/worker/index.html.erb
12
+ app/views/worker/_form.html.erb
@@ -0,0 +1,18 @@
1
+ table {
2
+ border-collapse: collapse;
3
+ border: 1px solid black;
4
+ }
5
+
6
+ th, td {
7
+ padding: 15px;
8
+ text-align: center;
9
+ }
10
+
11
+ th {
12
+ background-color: #f5f5f5;
13
+ color: black;
14
+ }
15
+
16
+ tr:nth-child(even) {
17
+ background-color: #f2f2f2
18
+ }
@@ -0,0 +1,6 @@
1
+ <h1>Editing <%= module_name %></h1>
2
+
3
+ <%%= render 'form' %>
4
+
5
+ <%%= link_to 'Show', <%= module_file_name %>_path(@<%= module_file_name %>) %> |
6
+ <%%= link_to 'Back', <%= module_file_name %>s_path %>
@@ -0,0 +1,52 @@
1
+ <%%= simple_form_for(@<%= module_file_name %>, url: <%= module_file_name %>_path(@<%= module_file_name %>)) do |form| %>
2
+ <table>
3
+ <tr>
4
+ <th>
5
+ Id
6
+ </th>
7
+ <td>
8
+ <%%= @<%= module_file_name %>.apiotics_instance %>
9
+ </td>
10
+ </tr>
11
+ <tr>
12
+ <th>
13
+ Name
14
+ </th>
15
+ <td>
16
+ <%%= @<%= module_file_name %>.name %>
17
+ </td>
18
+ </tr>
19
+ <% Apiotics.configuration.targets[module_name].keys.each do |key| %>
20
+ <tr>
21
+ <th rowspan='<%= Apiotics.configuration.targets[module_name][key].count %>'>
22
+ <%= key %>
23
+ </th>
24
+ <%%= form.simple_fields_for :<%= key.underscore.downcase %> do |fields| %>
25
+ <% n = 0 %>
26
+ <% Apiotics.configuration.targets[module_name][key].each do |interface| %>
27
+ <% if n != 0 %>
28
+ <tr>
29
+ <% end %>
30
+ <td>
31
+ <%%= fields.input :<%= interface %> %>
32
+ </td>
33
+ <% if n != 0 %>
34
+ </tr>
35
+ <% end %>
36
+ <% n += 1 %>
37
+ <% end %>
38
+ <%% end %>
39
+ </tr>
40
+ <% end %>
41
+ <tr>
42
+ <th>
43
+ &nbsp;
44
+ </th>
45
+ <td>
46
+ <div class="actions">
47
+ <%%= form.submit %>
48
+ </div>
49
+ </td>
50
+ </tr>
51
+ </table>
52
+ <%% end %>
@@ -0,0 +1,66 @@
1
+ <p id="notice"><%%= notice %></p>
2
+ <h1>
3
+ <%= module_name %>s
4
+ </h1>
5
+
6
+ <table>
7
+ <thead>
8
+ <tr>
9
+ <th style="border: 1px solid black;">
10
+ Id
11
+ </th>
12
+ <th style="border: 1px solid black;">
13
+ Name
14
+ </th>
15
+ <% Apiotics.configuration.targets[module_name].keys.each do |key| %>
16
+ <th colspan='<%= Apiotics.configuration.targets[module_name][key].count %>' style="border: 1px solid black;">
17
+ <%= key %>
18
+ </th>
19
+ <% end %>
20
+ <th style="border: 1px solid black;">
21
+ &nbsp;
22
+ </th>
23
+ </tr>
24
+ <tr>
25
+ <th>
26
+ &nbsp;
27
+ </th>
28
+ <th>
29
+ &nbsp;
30
+ </th>
31
+ <% Apiotics.configuration.targets[module_name].keys.each do |key| %>
32
+ <% Apiotics.configuration.targets[module_name][key].each do |interface| %>
33
+ <th>
34
+ <%= interface %>
35
+ </th>
36
+ <% end %>
37
+ <% end %>
38
+ <th>
39
+ &nbsp;
40
+ </th>
41
+ </tr>
42
+ </thead>
43
+ <tbody>
44
+ <%% @<%= module_file_name %>s.each do |object| %>
45
+ <tr id='<%%= object.apiotics_instance %>'>
46
+ <td>
47
+ <%%= object.apiotics_instance %>
48
+ </td>
49
+ <td>
50
+ <%%= object.name %>
51
+ </td>
52
+ <% Apiotics.configuration.targets[module_name].keys.each do |key| %>
53
+ <% Apiotics.configuration.targets[module_name][key].each do |interface| %>
54
+ <td class='<%= module_file_name %>-<%= key.underscore.downcase %>-<%= interface %>'>
55
+ <%%= object.<%= key.underscore.downcase %>.<%= interface %> %>
56
+ </td>
57
+ <% end %>
58
+ <% end %>
59
+ <td>
60
+ <%%= link_to "Edit", edit_<%= module_file_name %>_path(object)%>
61
+ <%%= link_to "Show", <%= module_file_name %>_path(object) %>
62
+ </td>
63
+ </tr>
64
+ <%% end %>
65
+ </tbody>
66
+ </table>