simbiotes 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +76 -1
  3. data/lib/generators/simbiotes/channel/USAGE +10 -0
  4. data/lib/generators/simbiotes/channel/channel_generator.rb +35 -0
  5. data/lib/generators/simbiotes/channel/templates/simbiotes_channel.rb.erb +9 -0
  6. data/lib/generators/simbiotes/channel/templates/simbiotes_channel_client.coffee.erb +12 -0
  7. data/lib/generators/simbiotes/channel/templates/simbiotes_channel_initializer.rb.erb +3 -0
  8. data/lib/generators/simbiotes/controller/USAGE +8 -0
  9. data/lib/generators/simbiotes/controller/controller_generator.rb +24 -0
  10. data/lib/generators/simbiotes/controller/templates/simbiotes_scaffold.rb.erb +60 -0
  11. data/lib/generators/simbiotes/create_model/USAGE +4 -2
  12. data/lib/generators/simbiotes/create_model/create_model_generator.rb +26 -0
  13. data/lib/generators/simbiotes/create_model/templates/create_module_model_table.rb.erb +8 -0
  14. data/lib/generators/simbiotes/create_model/templates/simbiotes_model.rb.erb +22 -0
  15. data/lib/generators/simbiotes/create_model/templates/simbiotes_module.rb.erb +1 -1
  16. data/lib/generators/simbiotes/create_model/templates/simbiotes_module_model.rb.erb +8 -0
  17. data/lib/generators/simbiotes/create_table/templates/create_table.rb.erb +1 -1
  18. data/lib/generators/simbiotes/view/USAGE +12 -0
  19. data/lib/generators/simbiotes/view/templates/default.css.erb +18 -0
  20. data/lib/generators/simbiotes/view/templates/edit.html.erb +6 -0
  21. data/lib/generators/simbiotes/view/templates/form.html.erb +28 -0
  22. data/lib/generators/simbiotes/view/templates/index.html.erb +57 -0
  23. data/lib/generators/simbiotes/view/templates/show.html.erb +47 -0
  24. data/lib/generators/simbiotes/view/view_generator.rb +26 -0
  25. data/lib/simbiotes/configuration.rb +2 -1
  26. data/lib/simbiotes/extract.rb +12 -2
  27. data/lib/simbiotes/insert.rb +2 -1
  28. data/lib/simbiotes/portal.rb +25 -18
  29. data/lib/simbiotes/version.rb +1 -1
  30. metadata +75 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 484f7f27f89451148e07395edce8fa2b116f6fef
4
- data.tar.gz: 261c4e13b133b9fe78c21b45f080e694034b8ef4
3
+ metadata.gz: 5175c82cbb859c8acf4e373e14853b27c27181fa
4
+ data.tar.gz: ca6226e2bdaa00d2e20cfe8e9362a785341fcfc8
5
5
  SHA512:
6
- metadata.gz: 83e5239515bac34def1a1d5eeb8d2c0e6c5de5de8b21bfc83847f9ea6a6adee90d5c231a455f882c55fb1e61aa013b45c6c119336ee49783f3ae14ebb245bdae
7
- data.tar.gz: 65e2b8ad8e291728e20fdbe411b62be7afd74906bbf3cf3614b421fce6c2b0dbef746c4d458c6867e70c95ba98a4013a78b7e09f7b9bf9984ecc38413fa1f36b
6
+ metadata.gz: ae1a9cb4215875a16ee809ee132f55004d4d28a0f8115c3a412ec338e127623cccb12a0ef900bd92db72e324e707893c1ef0224d8249ec7416b0f853b6dd132d
7
+ data.tar.gz: '09d629d03704e362da4f8f8ffcc5d672c8171bef955eec3a227c9d71c64b2241560b2d8761ef372f204c4fa09da9f213b6ccb2ec9bde400efb2fa8e3dd4b8945'
data/README.md CHANGED
@@ -80,7 +80,7 @@ In your console run:
80
80
  > Thermostat.sync_device_instances
81
81
  ```
82
82
 
83
- That will create a database record for each device you currently have.
83
+ That will create a database record for each device instance you currently have defined in for your Thermostat worker. If you have no instances defined, create one on the Thermostat worker page in the simbiotes.com portal.
84
84
 
85
85
  Next, exit your rails console by typing:
86
86
 
@@ -186,6 +186,81 @@ Now that you are synced with the device, you can set the device's Interfaces eas
186
186
 
187
187
  All of the communications to the device are taken care of for you. If the value of these Interfaces changes (if the ambient temperature rises or falls for example) then your database will be kept up to date via the communications server without needing to sync the device instance going forward.
188
188
 
189
+ ### Building a Web Scaffold
190
+
191
+ Now that you can communicate with your devices from the rails console, let's create a web scaffold so that you can communicate with them via your web browser.
192
+
193
+ If you haven't done it already, run
194
+
195
+ ```bash
196
+ > rails generate simple_form:install
197
+ ```
198
+
199
+ To install the form helpers we will use to build forms to edit device interfaces via the browser.
200
+
201
+ Once you've done that, you can run the simbiotes scaffold controller generator to generate a scaffold and views for your device.
202
+
203
+ ```bash
204
+ > rails generate simbiotes:controller Thermostat
205
+ ```
206
+
207
+ This command installs a default controller and views for your Thermostat. Once they are installed, you can see them in your browser by starting up your development web server.
208
+
209
+ ```bash
210
+ > rails server
211
+ ```
212
+
213
+ Then in your web browser of choice, navigate to http://localhost:3000/Thermostats. This page will show you a list of your Thermostat instances, as well as the current values of the different interfaces for your device. You can use the edit links for each device instance to change these values.
214
+
215
+ ### Adding Push Web Updates
216
+
217
+ Since we want to be able to see changes to our devices without refreshing our webpage manually, we can leverage Rails 5's ActionCable to push device updates to our page.
218
+
219
+ To do this, run:
220
+
221
+ ```bash
222
+ > rails generate simbiotes:channel Thermostat
223
+ ```
224
+
225
+ This command installs a configuration file, in this case app/channels/thermostat_channel.rb, to define an ActionCable channel for your Worker, in this case thermostat_channel, as well as a coffeescript file, in this case app/assets/javascripts/channels/thermostat.coffee, that defines how the browser will update information from the server on the page.
226
+
227
+ In order for the ActionCable messages to actually transmit to the browser, we need to install Redis. Redis is an open source in-memory data store that ActionCable uses to implement its PubSub messaging.
228
+
229
+ The easiest way to install Redis (if you are on a Mac) is:
230
+
231
+ ```bash
232
+ > brew install redis
233
+ ```
234
+
235
+ Then, once it is installed, run:
236
+
237
+ ```bash
238
+ > redis-server
239
+ ```
240
+
241
+ In your Rails application, edit your config/cable.yml file to look as follows:
242
+
243
+ ```yaml
244
+ development:
245
+ adapter: redis
246
+
247
+ test:
248
+ adapter: redis
249
+
250
+ production:
251
+ adapter: redis
252
+ ```
253
+
254
+ Next, open up your app/assets/javascripts/application.js file. Make sure the end of it looks like the following:
255
+
256
+ ```js
257
+ //= require jquery
258
+ //= require jquery_ujs
259
+ //= require_tree .
260
+ ```
261
+
262
+ Then, restart your Rails server.
263
+
189
264
 
190
265
  ## Contributing
191
266
  Contribution directions go here.
@@ -0,0 +1,10 @@
1
+ Description:
2
+ This generator creates channel files with the right code for Simbiotes interactions.
3
+
4
+ Example:
5
+ rails generate simbiotes:channel Worker Driver
6
+ rails generate simbiotes:channel Worker Script
7
+
8
+ This will create:
9
+ app/channel/worker/driver_channel.rb
10
+ app/assets/javascripts/channels/worker_driver.coffee
@@ -0,0 +1,35 @@
1
+ module Simbiotes
2
+ class ChannelGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+ argument :parent, :type => :string
5
+
6
+ def copy_channel_files
7
+ template "simbiotes_channel.rb.erb", "app/channels/#{module_file_name}_channel.rb"
8
+ template "simbiotes_channel_client.coffee.erb", "app/assets/javascripts/channels/#{module_file_name}.coffee"
9
+ template "simbiotes_channel_initializer.rb.erb", "config/initializers/simbiotes_channel.rb"
10
+ route "mount ActionCable.server => '/cable'"
11
+ end
12
+
13
+ private
14
+
15
+ def file_name
16
+ name.underscore
17
+ end
18
+
19
+ def module_file_name
20
+ parent.underscore
21
+ end
22
+
23
+ def class_name
24
+ name.classify
25
+ end
26
+
27
+ def module_name
28
+ parent.classify
29
+ end
30
+
31
+ def table_prefix
32
+ parent.underscore + "_"
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,9 @@
1
+ class <%= module_name + "Channel" %> < ApplicationCable::Channel
2
+ def subscribed
3
+ stream_from "<%= "#{module_file_name}_channel" %>"
4
+ end
5
+
6
+ def unsubscribed
7
+ # Any cleanup needed when channel is unsubscribed
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ App.alert = App.cable.subscriptions.create('<%= "#{module_name}" + "Channel" %>',
2
+ connected: ->
3
+ # Called when the subscription is ready for use on the server
4
+ return
5
+ disconnected: ->
6
+ # Called when the subscription has been terminated by the server
7
+ return
8
+ received: (data) ->
9
+
10
+ # Called when there's incoming data on the websocket for this channel
11
+ return
12
+ )
@@ -0,0 +1,3 @@
1
+ Simbiotes.configure do |config|
2
+ config.push = true
3
+ end
@@ -0,0 +1,8 @@
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 simbiotes:scaffold Worker
6
+
7
+ This will create:
8
+ app/controllers/worker.rb
@@ -0,0 +1,24 @@
1
+ module Simbiotes
2
+ class ControllerGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+ argument :parent, :type => :string
5
+
6
+ def copy_scaffold_files
7
+ @models = Simbiotes.configuration.targets[module_name.to_s]
8
+ template "simbiotes_scaffold.rb.erb", "app/controllers/#{module_file_name}/#{module_file_name.pluralize}_controller.rb"
9
+ generate "simbiotes:view", "#{parent}"
10
+ route "scope module: :#{module_file_name} do \n\t\tresources :#{module_file_name}s\n\tend"
11
+ end
12
+
13
+ private
14
+
15
+ def module_file_name
16
+ parent.underscore
17
+ end
18
+
19
+ def module_name
20
+ parent.classify
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,60 @@
1
+ module <%= module_name %>
2
+ class <%= module_name.pluralize + "Controller"%> < ApplicationController
3
+ before_action <%= ":set_" + module_file_name %>, only: [:show, :edit, :update, :destroy]
4
+
5
+ # GET /alert/leds
6
+ def index
7
+ @<%= module_file_name + "s" %> = <%= "::" + module_name + "::" + module_name + ".all" %>
8
+ end
9
+
10
+ # GET /alert/leds/1
11
+ def show
12
+ end
13
+
14
+ # GET /alert/leds/new
15
+ def new
16
+ redirect_to <%= module_file_name %>s_url, notice: 'You are not authorized to do that.'
17
+ end
18
+
19
+ # GET /alert/leds/1/edit
20
+ def edit
21
+ end
22
+
23
+ # POST /alert/leds
24
+ def create
25
+ @<%= module_file_name %> = <%= "::" + module_name + "::" + module_name + ".new(#{module_file_name}_params)" %>
26
+
27
+ if @<%= module_file_name %>.save
28
+ redirect_to <%= module_file_name %>_path(@<%= module_file_name %>), notice: '<%= module_name %> was successfully created.'
29
+ else
30
+ render :new
31
+ end
32
+ end
33
+
34
+ # PATCH/PUT /alert/leds/1
35
+ def update
36
+ if @<%= module_file_name %>.update(<%= module_file_name %>_params)
37
+ redirect_to <%= module_file_name %>_path(@<%= module_file_name %>), notice: '<%= module_name %> was successfully updated.'
38
+ else
39
+ render :edit
40
+ end
41
+ end
42
+
43
+ # DELETE /alert/leds/1
44
+ def destroy
45
+ @<%= module_file_name %>.destroy
46
+ redirect_to <%= module_file_name %>s_url, notice: '<%= module_file_name %> was successfully destroyed.'
47
+ end
48
+
49
+ private
50
+ # Use callbacks to share common setup or constraints between actions.
51
+ def set_<%= module_file_name %>
52
+ @<%= module_file_name %> = <%= "::" + module_name + "::" + module_name + ".find(params[:id])" %>
53
+ end
54
+
55
+ # Only allow a trusted parameter "white list" through.
56
+ def <%= module_file_name %>_params
57
+ params.fetch(:<%= module_file_name %>, {}).permit(:id, :simbiotes_instance<% Simbiotes.configuration.targets[module_name].keys.each do |key| %>, :<%= key.downcase %>_attributes => <%= Simbiotes.configuration.targets[module_name][key] %><% end %>)
58
+ end
59
+ end
60
+ end
@@ -2,7 +2,9 @@ Description:
2
2
  This generator creates model files with the right code for Simbiotes interactions.
3
3
 
4
4
  Example:
5
- rails generate simbiotes:model Thing
5
+ rails generate simbiotes:model Worker Driver
6
+ rails generate simbiotes:model Worker Script
6
7
 
7
8
  This will create:
8
- app/models/thing.rb
9
+ app/models/worker.rb
10
+ app/models/worker/driver.rb
@@ -9,7 +9,12 @@ module Simbiotes
9
9
  if portal == "true"
10
10
  @c = Simbiotes.get_attributes(parent, name)
11
11
  end
12
+ @targets = Simbiotes::Portal.parse_all_interfaces
12
13
  template "simbiotes_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 "simbiotes_module_model.rb.erb", "app/models/#{module_file_name}/#{module_file_name}.rb"
13
18
  template "simbiotes_model.rb.erb", "app/models/#{module_file_name}/#{file_name}.rb"
14
19
  unless Simbiotes.configuration.local_logging == false
15
20
  if portal == "true"
@@ -46,5 +51,26 @@ module Simbiotes
46
51
  def table_prefix
47
52
  parent.underscore + "_"
48
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
+
49
75
  end
50
76
  end
@@ -0,0 +1,8 @@
1
+ class Create<%= plural_module_name %> < ActiveRecord::Migration[5.1]
2
+ def change
3
+ create_table :<%= plural_table_name %> do |t|
4
+ t.string :simbiotes_instance
5
+ t.timestamps
6
+ end
7
+ end
8
+ end
@@ -4,8 +4,10 @@ module <%= module_name %>
4
4
  <%unless @c == nil %><% unless Simbiotes.configuration.local_logging == false %><% @c[:attributes].each do |k,v| %>
5
5
  has_many :<%= class_name.underscore.downcase.gsub(" ", "_") + "_#{k.underscore.downcase.gsub(" ", "_")}_logs"%>, dependent: :destroy
6
6
  <% end %><% end %><% end %>
7
+ belongs_to :<%= module_name.underscore.downcase.gsub(" ", "_")%>
7
8
  attr_accessor :skip_extract
8
9
  after_commit :extract, unless: :skip_extract
10
+ after_commit :channel_push
9
11
  <% unless @c == nil %><% @c[:attributes].each do |k,v| %><% unless v[:values] == "" %>validates :<%= k.downcase.gsub(" ", "_").underscore %>, inclusion: { in: %w(<%= v[:values].join(" ") %>,
10
12
  message: "%{value} is not a valid <%= k %>" }<% end %><% unless v[:range] == "" %>
11
13
  validates :<%= k.gsub(" ", "_").underscore %>, inclusion: { in: <%= v[:range] %>,
@@ -22,6 +24,26 @@ module <%= module_name %>
22
24
  def extract
23
25
  Simbiotes::Extract.send(self)
24
26
  end
27
+
28
+ def channel_push
29
+ if Simbiotes.configuration.push == true
30
+ interfaces = Hash.new
31
+ puts self.previous_changes
32
+ self.previous_changes.each do |k,v|
33
+ if Simbiotes::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.downcase.underscore.gsub(" ", "_")}_channel",
39
+ simbiotes_instance: self.<%= module_name.underscore.downcase.gsub(" ", "_")%>.simbiotes_instance,
40
+ worker_name: self.class.parent.to_s.downcase.underscore.gsub(" ", "_"),
41
+ model_name: self.class.name.demodulize.to_s.downcase.underscore.gsub(" ", "_"),
42
+ interface: k,
43
+ value: v
44
+ end
45
+ end
46
+ end
25
47
 
26
48
  end
27
49
  end
@@ -6,5 +6,5 @@ module <%= module_name %>
6
6
  def self.sync_device_instances
7
7
  Simbiotes.sync_device_instances(self.name)
8
8
  end
9
-
9
+
10
10
  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
@@ -9,7 +9,7 @@ class Create<%= plural_class_name %> < ActiveRecord::Migration[5.1]
9
9
  t.string :<%= k %>_status
10
10
  t.string :<%= k %>_action
11
11
  <% end %>
12
- t.string :simbiotes_instance
12
+ t.integer :<%= parent.underscore.downcase.gsub(" ", "_") + "_id" %>
13
13
  t.timestamps
14
14
  end
15
15
  end
@@ -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 simbiotes: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,28 @@
1
+ <%%= simple_form_for(@<%= module_file_name %>, url: <%= module_file_name %>_path(@<%= module_file_name %>)) do |form| %>
2
+ <table>
3
+ <% Simbiotes.configuration.targets[module_name].keys.each do |key| %>
4
+ <tr>
5
+ <th rowspan='<%= Simbiotes.configuration.targets[module_name][key].count %>'>
6
+ <%= key %>
7
+ </th>
8
+ <%%= form.simple_fields_for :<%= key.downcase %> do |fields| %>
9
+ <% Simbiotes.configuration.targets[module_name][key].each do |interface| %>
10
+ <td>
11
+ <%%= fields.input :<%= interface %> %>
12
+ </td>
13
+ <% end %>
14
+ <%% end %>
15
+ </tr>
16
+ <% end %>
17
+ <tr>
18
+ <th>
19
+ &nbsp;
20
+ </th>
21
+ <td>
22
+ <div class="actions">
23
+ <%%= form.submit %>
24
+ </div>
25
+ </td>
26
+ </tr>
27
+ </table>
28
+ <%% end %>
@@ -0,0 +1,57 @@
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
+ <% Simbiotes.configuration.targets[module_name].keys.each do |key| %>
13
+ <th colspan='<%= Simbiotes.configuration.targets[module_name][key].count %>' style="border: 1px solid black;">
14
+ <%= key %>
15
+ </th>
16
+ <% end %>
17
+ <th style="border: 1px solid black;">
18
+ &nbsp;
19
+ </th>
20
+ </tr>
21
+ <tr>
22
+ <th>
23
+ &nbsp;
24
+ </th>
25
+ <% Simbiotes.configuration.targets[module_name].keys.each do |key| %>
26
+ <% Simbiotes.configuration.targets[module_name][key].each do |interface| %>
27
+ <th>
28
+ <%= interface %>
29
+ </th>
30
+ <% end %>
31
+ <% end %>
32
+ <th>
33
+ &nbsp;
34
+ </th>
35
+ </tr>
36
+ </thead>
37
+ <tbody>
38
+ <%% @<%= module_file_name %>s.each do |object| %>
39
+ <tr id='<%%= object.simbiotes_instance %>'>
40
+ <td>
41
+ <%%= object.simbiotes_instance %>
42
+ </td>
43
+ <% Simbiotes.configuration.targets[module_name].keys.each do |key| %>
44
+ <% Simbiotes.configuration.targets[module_name][key].each do |interface| %>
45
+ <td class='<%= module_file_name %>-<%= key.downcase %>-<%= interface %>'>
46
+ <%%= object.<%= key.downcase %>.<%= interface %> %>
47
+ </td>
48
+ <% end %>
49
+ <% end %>
50
+ <td>
51
+ <%%= link_to "Edit", edit_<%= module_file_name %>_path(object)%>
52
+ <%%= link_to "Show", <%= module_file_name %>_path(object) %>
53
+ </td>
54
+ </tr>
55
+ <%% end %>
56
+ </tbody>
57
+ </table>
@@ -0,0 +1,47 @@
1
+ <p id="notice"><%%= notice %></p>
2
+ <h1>
3
+ <%= module_name %>
4
+ </h1>
5
+ <table>
6
+ <thead>
7
+ <tr>
8
+ <th style="border: 1px solid black;">
9
+ Id
10
+ </th>
11
+ <% Simbiotes.configuration.targets[module_name].keys.each do |key| %>
12
+ <th colspan='<%= Simbiotes.configuration.targets[module_name][key].count %>' style="border: 1px solid black;">
13
+ <%= key %>
14
+ </th>
15
+ <% end %>
16
+ </tr>
17
+ <tr>
18
+ <th>
19
+ &nbsp;
20
+ </th>
21
+ <% Simbiotes.configuration.targets[module_name].keys.each do |key| %>
22
+ <% Simbiotes.configuration.targets[module_name][key].each do |interface| %>
23
+ <th>
24
+ <%= interface %>
25
+ </th>
26
+ <% end %>
27
+ <% end %>
28
+ </tr>
29
+ </thead>
30
+ <tbody>
31
+ <tr id='<%%= @<%= module_file_name %>.simbiotes_instance %>'>
32
+ <td>
33
+ <%%= @<%= module_file_name %>.simbiotes_instance %>
34
+ </td>
35
+ <% Simbiotes.configuration.targets[module_name].keys.each do |key| %>
36
+ <% Simbiotes.configuration.targets[module_name][key].each do |interface| %>
37
+ <td class='<%= module_file_name %>-<%= key.downcase %>-<%= interface %>'>
38
+ <%%= @<%= module_file_name %>.<%= key.downcase %>.<%= interface %> %>
39
+ </td>
40
+ <% end %>
41
+ <% end %>
42
+ </tr>
43
+ </tbody>
44
+ </table>
45
+
46
+ <%%= link_to 'Edit', edit_<%= module_file_name %>_path(@<%= module_file_name %>) %> |
47
+ <%%= link_to 'Back', <%= module_file_name %>s_path %>
@@ -0,0 +1,26 @@
1
+ module Simbiotes
2
+ class ViewGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+ argument :parent, :type => :string
5
+
6
+ def copy_scaffold_files
7
+ @models = Simbiotes.configuration.targets[module_name.to_s]
8
+ template "show.html.erb", "app/views/#{module_file_name}/#{module_file_name.pluralize}/show.html.erb"
9
+ template "edit.html.erb", "app/views/#{module_file_name}/#{module_file_name.pluralize}/edit.html.erb"
10
+ template "index.html.erb", "app/views/#{module_file_name}/#{module_file_name.pluralize}/index.html.erb"
11
+ template "form.html.erb", "app/views/#{module_file_name}/#{module_file_name.pluralize}/_form.html.erb"
12
+ template "default.css.erb", "app/assets/stylesheets/#{module_file_name}.css"
13
+ end
14
+
15
+ private
16
+
17
+ def module_file_name
18
+ parent.underscore
19
+ end
20
+
21
+ def module_name
22
+ parent.classify
23
+ end
24
+
25
+ end
26
+ end
@@ -1,7 +1,7 @@
1
1
  module Simbiotes
2
2
  class Configuration
3
3
 
4
- attr_accessor :public_key, :private_key, :local_logging, :targets, :local_port, :server, :server_port, :portal
4
+ attr_accessor :public_key, :private_key, :local_logging, :targets, :local_port, :server, :server_port, :portal, :push
5
5
 
6
6
  def initialize
7
7
  @public_key = nil
@@ -12,6 +12,7 @@ module Simbiotes
12
12
  @server = "rgs.microarx.com"
13
13
  @server_port = 8000
14
14
  @portal = "http://www.simbiotes.com/"
15
+ @push = false
15
16
  end
16
17
 
17
18
  end
@@ -8,7 +8,7 @@ module Simbiotes
8
8
  interfaces = Hash.new
9
9
  puts object.previous_changes
10
10
  object.previous_changes.each do |k,v|
11
- if Simbiotes.configuration.targets[object.class.parent.to_s][object.class.name.demodulize.to_s].include?(k) || Simbiotes.configuration.targets[object.class.parent.to_s][object.class.name.demodulize.to_s].include?(k.titleize)
11
+ if Simbiotes::Extract.is_target(object, k)
12
12
  interfaces[k] = v[1].to_s
13
13
  end
14
14
  end
@@ -17,6 +17,14 @@ module Simbiotes
17
17
  end
18
18
  end
19
19
 
20
+ def self.is_target(object, k)
21
+ if Simbiotes.configuration.targets[object.class.parent.to_s][object.class.name.demodulize.to_s].include?(k) || Simbiotes.configuration.targets[object.class.parent.to_s][object.class.name.demodulize.to_s].include?(k.titleize)
22
+ return true
23
+ else
24
+ return false
25
+ end
26
+ end
27
+
20
28
  def self.get(object, time0= nil, time1= nil)
21
29
  object.accessed_fields.each do |field|
22
30
  v = Array.new
@@ -30,9 +38,11 @@ module Simbiotes
30
38
 
31
39
  def self.fire(object, interfaces, a, time0= nil, time1= nil)
32
40
  if Simbiotes.configuration.targets[object.class.parent.to_s] != nil
41
+ k = "#{object.class.parent}::#{object.class.parent}".constantize
42
+ i = "#{object.class.parent}".demodulize.gsub(" ","_").downcase + "_id"
33
43
  msg = {
34
44
  "action" => a,
35
- "instance" => object.simbiotes_instance,
45
+ "instance" => k.find(object.send(i)).simbiotes_instance,
36
46
  "driver" => object.class.name.to_s,
37
47
  "interface" => interfaces,
38
48
  }
@@ -33,7 +33,8 @@ module Simbiotes
33
33
  def find_record
34
34
  begin
35
35
  klass = @class.classify.constantize
36
- @record = klass.find_by(simbiotes_instance: @id)
36
+ master_record = (@class.parent.to_s + "::" + @class.parent.to_s).classify.constantize.find_by(simbiotes_instance: @id)
37
+ @record = master_record.send(klass.demodulize.downcase)
37
38
  rescue => e
38
39
  puts e
39
40
  end
@@ -88,24 +88,31 @@ module Simbiotes
88
88
  end
89
89
 
90
90
  def self.sync_device_instances(worker_name)
91
- instance_hash = JSON.parse(HTTParty.post("#{Simbiotes.configuration.portal}api/workers", :query => {:public_key => Simbiotes.configuration.public_key, :private_key => Simbiotes.configuration.private_key}).body)
92
- Simbiotes.configuration.targets[worker_name].keys.each do |key|
93
- klass = (worker_name + "::" + key).constantize rescue nil
94
- unless klass == nil
95
- instance_ids = Array.new
96
- instance_hash[worker_name].each do |instance_id,status|
97
- instance_ids << instance_id
98
- end
99
- stale_instances = klass.where.not(simbiotes_instance: instance_ids)
100
- stale_instances.destroy_all
101
- instance_ids.each do |instance_id|
102
- i = klass.find_by(simbiotes_instance: instance_id)
103
- if i == nil
104
- i = klass.new
105
- i.simbiotes_instance = instance_id
106
- i.skip_extract = true
107
- i.save(:validate => false)
108
- i.skip_extract = false
91
+ instance_hash = JSON.parse(HTTParty.post("#{Simbiotes.configuration.portal}api/workers", :query => {:public_key => Simbiotes.configuration.public_key, :private_key => Simbiotes.configuration.private_key}).body)
92
+ klass = (worker_name.to_s + "::" + worker_name.to_s).constantize rescue nil
93
+ unless klass == nil
94
+ instance_ids = Array.new
95
+ instance_hash[worker_name].each do |instance_id,status|
96
+ instance_ids << instance_id
97
+ end
98
+ stale_instances = klass.where.not(simbiotes_instance: instance_ids)
99
+ stale_instances.destroy_all
100
+ instance_ids.each do |instance_id|
101
+ i = klass.find_by(simbiotes_instance: instance_id)
102
+ if i == nil
103
+ i = klass.new
104
+ i.simbiotes_instance = instance_id
105
+ i.save(:validate => false)
106
+ Simbiotes.configuration.targets[worker_name].keys.each do |key|
107
+ subklass = (worker_name + "::" + key).constantize rescue nil
108
+ unless subklass == nil
109
+ s = subklass.new
110
+ k = worker_name.downcase.gsub(" ","_").to_s + "_id="
111
+ s.send((k).to_sym, i.id)
112
+ s.skip_extract = true
113
+ s.save(:validate => false)
114
+ s.skip_extract = false
115
+ end
109
116
  end
110
117
  end
111
118
  end
@@ -1,3 +1,3 @@
1
1
  module Simbiotes
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simbiotes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - MicroArx Corporation
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-14 00:00:00.000000000 Z
11
+ date: 2017-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -66,6 +66,34 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '2.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simple_form
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: redis
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: pg
71
99
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +108,34 @@ dependencies:
80
108
  - - ">="
81
109
  - !ruby/object:Gem::Version
82
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: coffee-rails
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: puma
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
83
139
  description: "."
84
140
  email: info@microarx.com
85
141
  executables: []
@@ -89,11 +145,21 @@ files:
89
145
  - MIT-LICENSE
90
146
  - README.md
91
147
  - Rakefile
148
+ - lib/generators/simbiotes/channel/USAGE
149
+ - lib/generators/simbiotes/channel/channel_generator.rb
150
+ - lib/generators/simbiotes/channel/templates/simbiotes_channel.rb.erb
151
+ - lib/generators/simbiotes/channel/templates/simbiotes_channel_client.coffee.erb
152
+ - lib/generators/simbiotes/channel/templates/simbiotes_channel_initializer.rb.erb
153
+ - lib/generators/simbiotes/controller/USAGE
154
+ - lib/generators/simbiotes/controller/controller_generator.rb
155
+ - lib/generators/simbiotes/controller/templates/simbiotes_scaffold.rb.erb
92
156
  - lib/generators/simbiotes/create_model/USAGE
93
157
  - lib/generators/simbiotes/create_model/create_model_generator.rb
158
+ - lib/generators/simbiotes/create_model/templates/create_module_model_table.rb.erb
94
159
  - lib/generators/simbiotes/create_model/templates/simbiotes_logs_model.rb.erb
95
160
  - lib/generators/simbiotes/create_model/templates/simbiotes_model.rb.erb
96
161
  - lib/generators/simbiotes/create_model/templates/simbiotes_module.rb.erb
162
+ - lib/generators/simbiotes/create_model/templates/simbiotes_module_model.rb.erb
97
163
  - lib/generators/simbiotes/create_table/USAGE
98
164
  - lib/generators/simbiotes/create_table/create_table_generator.rb
99
165
  - lib/generators/simbiotes/create_table/templates/create_logs_table.rb.erb
@@ -117,6 +183,13 @@ files:
117
183
  - lib/generators/simbiotes/script/templates/script.rb.erb
118
184
  - lib/generators/simbiotes/script/templates/server.rb
119
185
  - lib/generators/simbiotes/script/templates/server_control.rb
186
+ - lib/generators/simbiotes/view/USAGE
187
+ - lib/generators/simbiotes/view/templates/default.css.erb
188
+ - lib/generators/simbiotes/view/templates/edit.html.erb
189
+ - lib/generators/simbiotes/view/templates/form.html.erb
190
+ - lib/generators/simbiotes/view/templates/index.html.erb
191
+ - lib/generators/simbiotes/view/templates/show.html.erb
192
+ - lib/generators/simbiotes/view/view_generator.rb
120
193
  - lib/simbiotes.rb
121
194
  - lib/simbiotes/client.rb
122
195
  - lib/simbiotes/configuration.rb