apiotics-test 0.1.49
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 +58 -0
- data/lib/apiotics/client.rb +20 -0
- data/lib/apiotics/configuration.rb +23 -0
- data/lib/apiotics/extract.rb +107 -0
- data/lib/apiotics/hardware.rb +109 -0
- data/lib/apiotics/insert.rb +115 -0
- data/lib/apiotics/parse.rb +20 -0
- data/lib/apiotics/portal.rb +217 -0
- data/lib/apiotics/railtie.rb +14 -0
- data/lib/apiotics/server.rb +238 -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 +25 -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 +14 -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 +9 -0
- data/lib/generators/apiotics/create_table/USAGE +9 -0
- data/lib/generators/apiotics/create_table/create_table_generator.rb +62 -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 +29 -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_parents.rb.erb +3 -0
- data/lib/generators/apiotics/initializer/templates/apiotics_settings.rb.erb +9 -0
- data/lib/generators/apiotics/initializer/templates/apiotics_targets.rb.erb +4 -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/scaffold/scaffold_generator.rb +23 -0
- data/lib/generators/apiotics/scaffold/templates/USAGE +0 -0
- data/lib/generators/apiotics/script/USAGE +8 -0
- data/lib/generators/apiotics/script/script_generator.rb +45 -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/install_firmware.rake +10 -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 +52 -0
- data/lib/generators/apiotics/view/templates/index.html.erb +66 -0
- data/lib/generators/apiotics/view/templates/show.html.erb +56 -0
- data/lib/generators/apiotics/view/view_generator.rb +26 -0
- data/lib/tasks/simbiotes_tasks.rake +4 -0
- metadata +256 -0
@@ -0,0 +1,76 @@
|
|
1
|
+
module Apiotics
|
2
|
+
class CreateModelGenerator < Rails::Generators::Base
|
3
|
+
source_root File.expand_path('../templates', __FILE__)
|
4
|
+
argument :parent, :type => :string
|
5
|
+
argument :name, :type => :string
|
6
|
+
argument :portal, :type => :string, :required => false
|
7
|
+
|
8
|
+
def copy_model_file
|
9
|
+
if portal == "true"
|
10
|
+
@c = Apiotics.get_attributes(parent, name)
|
11
|
+
end
|
12
|
+
@targets = Apiotics::Portal.parse_all_interfaces
|
13
|
+
template "apiotics_module.rb.erb", "app/models/#{module_file_name}.rb"
|
14
|
+
unless File.exist?("app/models/#{module_file_name}/#{module_file_name}.rb")
|
15
|
+
template "create_module_model_table.rb.erb", "db/migrate/#{date_string}_create_#{plural_name}.rb"
|
16
|
+
end
|
17
|
+
template "apiotics_module_model.rb.erb", "app/models/#{module_file_name}/#{module_file_name}.rb"
|
18
|
+
template "apiotics_model.rb.erb", "app/models/#{module_file_name}/#{file_name}.rb"
|
19
|
+
unless Apiotics.configuration.local_logging == false
|
20
|
+
if portal == "true"
|
21
|
+
@c[:attributes].each do |k,v|
|
22
|
+
@k = k
|
23
|
+
@v = v
|
24
|
+
template "apiotics_logs_model.rb.erb", "app/models/#{module_file_name}/#{file_name}_#{@k.underscore.downcase.gsub(" ","_")}_log.rb"
|
25
|
+
end
|
26
|
+
else
|
27
|
+
@k = name
|
28
|
+
template "apiotics_logs_model.rb.erb", "app/models/#{module_file_name}/#{file_name}_#{@k.underscore.downcase.gsub(" ","_")}_log.rb"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def file_name
|
36
|
+
name.underscore
|
37
|
+
end
|
38
|
+
|
39
|
+
def module_file_name
|
40
|
+
parent.underscore
|
41
|
+
end
|
42
|
+
|
43
|
+
def class_name
|
44
|
+
name.classify
|
45
|
+
end
|
46
|
+
|
47
|
+
def module_name
|
48
|
+
parent.classify
|
49
|
+
end
|
50
|
+
|
51
|
+
def table_prefix
|
52
|
+
parent.underscore + "_"
|
53
|
+
end
|
54
|
+
|
55
|
+
def plural_name
|
56
|
+
parent.underscore.pluralize
|
57
|
+
end
|
58
|
+
|
59
|
+
def plural_table_name
|
60
|
+
parent.underscore + "_" + parent.underscore.pluralize
|
61
|
+
end
|
62
|
+
|
63
|
+
def plural_class_name
|
64
|
+
parent.classify + name.classify.pluralize
|
65
|
+
end
|
66
|
+
|
67
|
+
def plural_module_name
|
68
|
+
parent.classify.pluralize
|
69
|
+
end
|
70
|
+
|
71
|
+
def date_string
|
72
|
+
date_string = DateTime.now.strftime("%Y%m%d%H%M%S")
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module <%= module_name %>
|
2
|
+
class <%= class_name %> < ApplicationRecord
|
3
|
+
<% unless @c == nil %># The method(s) that correspond to device interfaces are: <% @c[:attributes].each do |k,v| %><%=k.downcase.gsub(" ", "_")%> <% end %><% end %>
|
4
|
+
<%unless @c == nil %><% unless Apiotics.configuration.local_logging == false %><% @c[:attributes].each do |k,v| %>
|
5
|
+
has_many :<%= class_name.underscore.downcase.gsub(" ", "_") + "_#{k.underscore.downcase.gsub(" ", "_")}_logs"%>, dependent: :destroy
|
6
|
+
<% end %><% end %><% end %>
|
7
|
+
belongs_to :<%= module_name.underscore.downcase.gsub(" ", "_")%>
|
8
|
+
attr_accessor :skip_extract
|
9
|
+
after_commit :extract, unless: :skip_extract
|
10
|
+
after_commit :channel_push
|
11
|
+
<% unless @c == nil %><% @c[:attributes].each do |k,v| %><% unless v[:values] == "" %>validates :<%= k.downcase.gsub(" ", "_").underscore %>, inclusion: { in: %w(<%= v[:values].join(" ") %>,
|
12
|
+
message: "%{value} is not a valid <%= k %>" }<% end %><% unless v[:range] == "" %>
|
13
|
+
validates :<%= k.gsub(" ", "_").underscore %>, inclusion: { in: <%= v[:range] %>,
|
14
|
+
message: "%{value} is not within the range <%= v[:range] %>" }<% end %><% if v[:type] == "enum" %>
|
15
|
+
enum <%= k.gsub(" ", "_").underscore %>: <%= v[:values] %><% end %><% end %><% end %>
|
16
|
+
|
17
|
+
|
18
|
+
def sync
|
19
|
+
Apiotics.sync(self)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def extract
|
25
|
+
Apiotics::Extract.send(self)
|
26
|
+
end
|
27
|
+
|
28
|
+
def channel_push
|
29
|
+
if Apiotics.configuration.push == true
|
30
|
+
interfaces = Hash.new
|
31
|
+
puts self.previous_changes
|
32
|
+
self.previous_changes.each do |k,v|
|
33
|
+
if Apiotics::Extract.is_target(self, k)
|
34
|
+
interfaces[k] = v[1].to_s
|
35
|
+
end
|
36
|
+
end
|
37
|
+
interfaces.each do |k,v|
|
38
|
+
ActionCable.server.broadcast "#{self.class.parent.to_s.underscore.downcase.gsub(" ", "_")}_channel",
|
39
|
+
apiotics_instance: self.<%= module_name.underscore.downcase.gsub(" ", "_")%>.apiotics_instance,
|
40
|
+
worker_name: self.class.parent.to_s.underscore.downcase.gsub(" ", "_"),
|
41
|
+
model_name: self.class.name.demodulize.to_s.underscore.downcase.gsub(" ", "_"),
|
42
|
+
interface: k,
|
43
|
+
value: v
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module <%= module_name %>
|
2
|
+
def self.table_name_prefix
|
3
|
+
'<%= table_prefix %>'
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.sync_device_instances
|
7
|
+
Apiotics.sync_device_instances(self.name)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.sync_devices
|
11
|
+
Apiotics.sync_device_instances(self.name, true)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
module <%= module_name %>
|
2
|
+
class <%= module_name %> < ApplicationRecord
|
3
|
+
<% @targets[module_name].keys.each do |key| %>
|
4
|
+
has_one :<%= key.underscore.downcase.gsub(" ", "_")%>, dependent: :destroy
|
5
|
+
accepts_nested_attributes_for :<%= key.underscore.downcase.gsub(" ", "_")%>
|
6
|
+
<% end %>
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
Description:
|
2
|
+
Creates a database table with attributes that Apiotics requires.
|
3
|
+
|
4
|
+
Example:
|
5
|
+
rails generate apiotics:create_table Table attribute:type attribute:type ... attribute:type
|
6
|
+
|
7
|
+
This will create:
|
8
|
+
db/migrate/{datetime_stamp}_create_table.rb
|
9
|
+
db/migrate/{datetime_stamp}_create_table_logs.rb
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Apiotics
|
2
|
+
class CreateTableGenerator < 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 copy_create_table_files
|
9
|
+
@attribute_map = {
|
10
|
+
"smallint" => {"kind" => "integer", "limit" => 2},
|
11
|
+
"bigint" => {"kind" => "integer", "limit" => 8},
|
12
|
+
"uint8_t" => {"kind" => "integer", "limit" => 2},
|
13
|
+
"uint16_t" => {"kind" => "integer", "limit" => 4},
|
14
|
+
"uint32_t" => {"kind" => "integer", "limit" => 8},
|
15
|
+
"int16_t" => {"kind" => "integer", "limit" => 2},
|
16
|
+
"int32_t" => {"kind" => "integer", "limit" => 4},
|
17
|
+
"int_64t" => {"kind" => "integer", "limit" => 8}
|
18
|
+
}
|
19
|
+
template "create_table.rb.erb", "db/migrate/#{date_string}_create_#{plural_name}.rb"
|
20
|
+
unless Apiotics.configuration.local_logging == false
|
21
|
+
sleep 1
|
22
|
+
attributes.each do |k,v|
|
23
|
+
@k = k
|
24
|
+
@v = v
|
25
|
+
template "create_logs_table.rb.erb", "db/migrate/#{date_string}_create_#{table_name}_#{@k}_logs.rb"
|
26
|
+
sleep 1
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def date_string
|
34
|
+
date_string = DateTime.now.strftime("%Y%m%d%H%M%S")
|
35
|
+
end
|
36
|
+
|
37
|
+
def plural_name
|
38
|
+
parent.underscore + "_" + name.underscore.pluralize
|
39
|
+
end
|
40
|
+
|
41
|
+
def table_name
|
42
|
+
parent.underscore + "_" + name.underscore
|
43
|
+
end
|
44
|
+
|
45
|
+
def class_name
|
46
|
+
name.classify
|
47
|
+
end
|
48
|
+
|
49
|
+
def plural_class_name
|
50
|
+
parent.classify + name.classify.pluralize
|
51
|
+
end
|
52
|
+
|
53
|
+
def logs_class_name(k)
|
54
|
+
parent.classify + name.classify + k.classify + "Logs"
|
55
|
+
end
|
56
|
+
|
57
|
+
def logs_table_name(k)
|
58
|
+
parent.underscore + "_" + name.underscore + "_" + k.underscore + "_" + "logs"
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class Create<%= logs_class_name(@k) %> < ActiveRecord::Migration[5.1]
|
2
|
+
def change
|
3
|
+
create_table :<%= logs_table_name(@k) %> do |t|
|
4
|
+
<% if @attribute_map[@v] != nil %>t.<%= @attribute_map[@v]["kind"] %> :<%= @k %>, limit: <%= @attribute_map[@v]["limit"] %><% else %>t.<%= @v %> :<%= @k %><% end %>
|
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 :<%= name.underscore.downcase %>_id
|
11
|
+
t.timestamps
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Create<%= plural_class_name %> < ActiveRecord::Migration[5.1]
|
2
|
+
def change
|
3
|
+
create_table :<%= plural_name %> do |t|
|
4
|
+
<% attributes.each do |k,v| %>
|
5
|
+
<% if @attribute_map[v] != nil %>t.<%= @attribute_map[v]["kind"] %> :<%= k %>, limit: <%= @attribute_map[v]["limit"] %><% else %>t.<%= v %> :<%= k %><% end %>
|
6
|
+
t.boolean :<%= k %>_ack
|
7
|
+
t.boolean :<%= k %>_complete
|
8
|
+
t.string :<%= k %>_timestamp
|
9
|
+
t.string :<%= k %>_status
|
10
|
+
t.string :<%= k %>_action
|
11
|
+
<% end %>
|
12
|
+
t.integer :<%= parent.underscore.downcase.gsub(" ", "_") + "_id" %>
|
13
|
+
t.timestamps
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,29 @@
|
|
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
|
+
@p = Apiotics::Portal.parse_parents
|
11
|
+
template "apiotics_parents.rb.erb", "config/initializers/apiotics_parents.rb"
|
12
|
+
else
|
13
|
+
template "apiotics.rb.erb", "config/initializers/apiotics.rb"
|
14
|
+
template "apiotics_settings.rb.erb", "db/migrate/#{date_string}_create_apiotics_settings.rb"
|
15
|
+
template "setting.rb.erb", "app/models/apiotics_setting.rb"
|
16
|
+
#template "apiotics_module.rb.erb", "app/models/apiotics.rb"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def date_string
|
25
|
+
date_string = DateTime.now.strftime("%Y%m%d%H%M%S")
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
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
|