apiotics 0.1.22
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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +260 -0
- data/Rakefile +33 -0
- data/lib/apiotics.rb +57 -0
- data/lib/apiotics/client.rb +20 -0
- data/lib/apiotics/configuration.rb +22 -0
- data/lib/apiotics/extract.rb +87 -0
- data/lib/apiotics/insert.rb +105 -0
- data/lib/apiotics/parse.rb +20 -0
- data/lib/apiotics/portal.rb +156 -0
- data/lib/apiotics/railtie.rb +14 -0
- data/lib/apiotics/server.rb +236 -0
- data/lib/apiotics/version.rb +3 -0
- data/lib/generators/apiotics/channel/USAGE +10 -0
- data/lib/generators/apiotics/channel/channel_generator.rb +35 -0
- data/lib/generators/apiotics/channel/templates/apiotics_channel.rb.erb +9 -0
- data/lib/generators/apiotics/channel/templates/apiotics_channel_client.coffee.erb +16 -0
- data/lib/generators/apiotics/channel/templates/apiotics_channel_initializer.rb.erb +3 -0
- data/lib/generators/apiotics/controller/USAGE +8 -0
- data/lib/generators/apiotics/controller/controller_generator.rb +24 -0
- data/lib/generators/apiotics/controller/templates/apiotics_scaffold.rb.erb +60 -0
- data/lib/generators/apiotics/create_model/USAGE +10 -0
- data/lib/generators/apiotics/create_model/create_model_generator.rb +76 -0
- data/lib/generators/apiotics/create_model/templates/apiotics_logs_model.rb.erb +7 -0
- data/lib/generators/apiotics/create_model/templates/apiotics_model.rb.erb +49 -0
- data/lib/generators/apiotics/create_model/templates/apiotics_module.rb.erb +10 -0
- data/lib/generators/apiotics/create_model/templates/apiotics_module_model.rb.erb +8 -0
- data/lib/generators/apiotics/create_model/templates/create_module_model_table.rb.erb +8 -0
- data/lib/generators/apiotics/create_table/USAGE +9 -0
- data/lib/generators/apiotics/create_table/create_table_generator.rb +52 -0
- data/lib/generators/apiotics/create_table/templates/create_logs_table.rb.erb +14 -0
- data/lib/generators/apiotics/create_table/templates/create_table.rb.erb +16 -0
- data/lib/generators/apiotics/initializer/USAGE +8 -0
- data/lib/generators/apiotics/initializer/initializer_generator.rb +27 -0
- data/lib/generators/apiotics/initializer/templates/apiotics.rb.erb +10 -0
- data/lib/generators/apiotics/initializer/templates/apiotics_module.rb.erb +6 -0
- data/lib/generators/apiotics/initializer/templates/apiotics_settings.rb.erb +9 -0
- data/lib/generators/apiotics/initializer/templates/apiotics_targets.rb.erb +3 -0
- data/lib/generators/apiotics/initializer/templates/setting.rb.erb +3 -0
- data/lib/generators/apiotics/install/USAGE +11 -0
- data/lib/generators/apiotics/install/install_generator.rb +11 -0
- data/lib/generators/apiotics/migration/USAGE +10 -0
- data/lib/generators/apiotics/migration/migration_generator.rb +54 -0
- data/lib/generators/apiotics/migration/templates/create_logs_table.rb.erb +14 -0
- data/lib/generators/apiotics/migration/templates/migrate_table.rb.erb +12 -0
- data/lib/generators/apiotics/model/USAGE +11 -0
- data/lib/generators/apiotics/model/model_generator.rb +58 -0
- data/lib/generators/apiotics/script/USAGE +8 -0
- data/lib/generators/apiotics/script/script_generator.rb +44 -0
- data/lib/generators/apiotics/script/templates/comm_server.rake +19 -0
- data/lib/generators/apiotics/script/templates/dev_comm_server.rake +19 -0
- data/lib/generators/apiotics/script/templates/dev_server.rb +8 -0
- data/lib/generators/apiotics/script/templates/dev_server_control.rb +7 -0
- data/lib/generators/apiotics/script/templates/publish_script.rake +6 -0
- data/lib/generators/apiotics/script/templates/script.rb.erb +12 -0
- data/lib/generators/apiotics/script/templates/server.rb +8 -0
- data/lib/generators/apiotics/script/templates/server_control.rb +7 -0
- data/lib/generators/apiotics/script/templates/test_comm_server.rake +19 -0
- data/lib/generators/apiotics/script/templates/test_server.rb +8 -0
- data/lib/generators/apiotics/script/templates/test_server_control.rb +7 -0
- data/lib/generators/apiotics/view/USAGE +12 -0
- data/lib/generators/apiotics/view/templates/default.css.erb +18 -0
- data/lib/generators/apiotics/view/templates/edit.html.erb +6 -0
- data/lib/generators/apiotics/view/templates/form.html.erb +36 -0
- data/lib/generators/apiotics/view/templates/index.html.erb +57 -0
- data/lib/generators/apiotics/view/templates/show.html.erb +47 -0
- data/lib/generators/apiotics/view/view_generator.rb +26 -0
- data/lib/tasks/simbiotes_tasks.rake +4 -0
- metadata +237 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
module Apiotics
|
2
|
+
class InitializerGenerator < Rails::Generators::Base
|
3
|
+
source_root File.expand_path('../templates', __FILE__)
|
4
|
+
argument :portal, :type => :string, :required => false
|
5
|
+
|
6
|
+
def copy_initializer_file
|
7
|
+
if portal == "true"
|
8
|
+
@c = Apiotics::Portal.parse_all_interfaces
|
9
|
+
template "apiotics_targets.rb.erb", "config/initializers/apiotics_targets.rb"
|
10
|
+
else
|
11
|
+
template "apiotics.rb.erb", "config/initializers/apiotics.rb"
|
12
|
+
template "apiotics_settings.rb.erb", "db/migrate/#{date_string}_create_apiotics_settings.rb"
|
13
|
+
template "setting.rb.erb", "app/models/apiotics_setting.rb"
|
14
|
+
#template "apiotics_module.rb.erb", "app/models/apiotics.rb"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def date_string
|
23
|
+
date_string = DateTime.now.strftime("%Y%m%d%H%M%S")
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
Apiotics.configure do |config|
|
2
|
+
config.public_key = nil #set this to an Environment variable
|
3
|
+
config.private_key = nil #set this to an Environment variable
|
4
|
+
config.local_port = 8001
|
5
|
+
config.server_port = 8000
|
6
|
+
config.tls = true
|
7
|
+
config.verify_peer = true
|
8
|
+
config.handshake = true
|
9
|
+
config.local_logging = true
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
Description:
|
2
|
+
Creates database migrations for Apiotics tables
|
3
|
+
|
4
|
+
Example:
|
5
|
+
rails generate apiotics:migration AddAttributeToTableName attribute:type attribute:type ... attribute:type
|
6
|
+
|
7
|
+
This will create:
|
8
|
+
db/migrate/{datetime_string}_migration_name.rb
|
9
|
+
|
10
|
+
The AddAttributeToTableName argument is flexible, but expects an existing Apiotics table name after the "To" portion of the name.
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Apiotics
|
2
|
+
class MigrationGenerator < Rails::Generators::Base
|
3
|
+
source_root File.expand_path('../templates', __FILE__)
|
4
|
+
argument :name, :type => :string
|
5
|
+
argument :attributes, :type => :hash, :required => true
|
6
|
+
|
7
|
+
def copy_create_table_files
|
8
|
+
template "migrate_table.rb.erb", "db/migrate/#{date_string}_#{underscore_name}.rb"
|
9
|
+
sleep 1
|
10
|
+
attributes.each do |k,v|
|
11
|
+
@k = k
|
12
|
+
@v = v
|
13
|
+
template "create_logs_table.rb.erb", "db/migrate/#{date_string}_#{underscore_name}_logs.rb"
|
14
|
+
sleep 1
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def date_string
|
21
|
+
date_string = DateTime.now.strftime("%Y%m%d%H%M%S")
|
22
|
+
end
|
23
|
+
|
24
|
+
def table_name
|
25
|
+
array = name.underscore.split('_')
|
26
|
+
i = 0
|
27
|
+
new_array = Array.new
|
28
|
+
marker = false
|
29
|
+
while i < array.length
|
30
|
+
if marker == true
|
31
|
+
new_array << array[i]
|
32
|
+
end
|
33
|
+
if array[i] == "to"
|
34
|
+
marker = true
|
35
|
+
end
|
36
|
+
i += 1
|
37
|
+
end
|
38
|
+
new_array.join('_')
|
39
|
+
end
|
40
|
+
|
41
|
+
def underscore_name
|
42
|
+
name.underscore
|
43
|
+
end
|
44
|
+
|
45
|
+
def class_name
|
46
|
+
name.classify
|
47
|
+
end
|
48
|
+
|
49
|
+
def logs_table_name(k)
|
50
|
+
table_name + "_" + k.underscore + "_" + "logs"
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
@@ -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,44 @@
|
|
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
|
+
FileUtils.chmod 0775, "lib/scripts/server_control.rb"
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def file_name
|
28
|
+
name.underscore
|
29
|
+
end
|
30
|
+
|
31
|
+
def class_name
|
32
|
+
name.classify
|
33
|
+
end
|
34
|
+
|
35
|
+
def parent_class_name
|
36
|
+
parent.classify
|
37
|
+
end
|
38
|
+
|
39
|
+
def parent_file_name
|
40
|
+
parent.underscore
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
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,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,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
|