hyper-mesh 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +59 -204
- data/config/routes.rb +1 -1
- data/docs/action_cable_quickstart.md +13 -36
- data/docs/configuration_details.md +62 -0
- data/docs/pusher_faker_quickstart.md +28 -0
- data/docs/pusher_quickstart.md +17 -0
- data/docs/simple_poller_quickstart.md +5 -0
- data/examples/words/Gemfile +4 -3
- data/examples/words/Gemfile.lock +33 -32
- data/examples/words/app/views/components.rb +4 -2
- data/examples/words/config/initializers/hyper_mesh.rb +14 -0
- data/examples/words/config/routes.rb +1 -1
- data/hyper-mesh-0.4.0.gem +0 -0
- data/lib/hyper-mesh.rb +2 -1
- data/lib/hypermesh/version.rb +1 -1
- data/lib/reactive_record/active_record/public_columns_hash.rb +2 -2
- data/lib/reactive_record/active_record/reactive_record/isomorphic_base.rb +1 -1
- data/lib/reactive_record/engine.rb +2 -4
- data/lib/reactive_record/permissions.rb +30 -7
- data/lib/synchromesh/client_drivers.rb +3 -5
- data/lib/synchromesh/connection.rb +34 -8
- data/lib/synchromesh/synchromesh.rb +11 -7
- data/lib/synchromesh/synchromesh_controller.rb +9 -1
- data/path_release_steps.md +9 -0
- data/reactive_record_test_app/Gemfile +2 -1
- data/reactive_record_test_app/Gemfile.lock +6 -6
- data/reactive_record_test_app/config/application.rb +0 -1
- data/reactive_record_test_app/config/initializers/hyper_mesh_legacy_behavior.rb +5 -0
- data/reactive_record_test_app/config/routes.rb +3 -3
- data/spec/reactive_record/edge_cases_spec.rb +1 -1
- data/spec/reactive_record/many_to_many_spec.rb +1 -1
- data/spec/reactive_record/revert_spec.rb +1 -0
- data/spec/reactive_record/update_associations_spec.rb +1 -0
- data/spec/reactive_record/update_scopes_spec.rb +1 -0
- data/spec/synchromesh/crud_access_regulation/broadcast_controls_access_spec.rb +0 -6
- data/spec/synchromesh/crud_access_regulation/model_policies_spec.rb +8 -6
- data/spec/synchromesh/integration/has_many_through_spec.rb +0 -4
- data/spec/test_app/config/routes.rb +1 -1
- data/work-in-progress-drinking.png +0 -0
- metadata +8 -4
- data/examples/words/config/initializers/synchromesh.rb +0 -5
- data/lib/synchromesh/reactive_record/permission_patches.rb +0 -43
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed2a9b3886af2207f09a5e8ce3db7cb0383c2617
|
4
|
+
data.tar.gz: 3aacee91de89e22c2279324f4fc4e8ae91eb658d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 029224667501009cc0e60988b14bbdfda286fa2f06ebf2f0d4ff78a07035925054724481dc538e0028b0a5952343f77f124ef463af3ad590d60bdab776bc621c
|
7
|
+
data.tar.gz: 2997bb5b724ded7d1ebbef695385161d49a75c52e86b9a1803e11e2c7dd04dcb4fad07fef5c94c0e0cbe6d09b83d020df3d942571d073f596aaa80abeb648e2c
|
data/README.md
CHANGED
@@ -1,38 +1,25 @@
|
|
1
1
|
# ![](https://avatars3.githubusercontent.com/u/15810526?v=3&s=40&raw=true)HyperMesh
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
|
4
|
+
[![Join the chat at https://gitter.im/reactrb/chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/reactrb/chat?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/hyper-mesh.svg)](https://badge.fury.io/rb/hyper-mesh)
|
6
|
+
|
7
|
+
HyperMesh gives your HyperReact components CRUD access to your server side ActiveRecord models, using the the standard ActiveRecord API.
|
8
|
+
In addition HyperMesh implements push notifications (via a number of possible
|
5
9
|
technologies) so changes to records on the server are dynamically pushed to all authorised clients.
|
6
10
|
|
7
11
|
*Its Isomorphic Ruby in action.*
|
8
12
|
|
9
|
-
In other words browser
|
13
|
+
In other words one browser creates, updates, or destroys a model, and the changes are persisted in
|
10
14
|
active record models and then broadcast to all other authorised clients.
|
11
15
|
|
12
|
-
## Quick Start Guides
|
13
|
-
|
14
|
-
Use one of the following guides if you are in a hurry to get going.
|
15
|
-
|
16
|
-
If you don't care about synchronizing clients (i.e you just want a simple single client CRUD type application) use this
|
17
|
-
[guide.](docs/no_synchronization_quickstart.md)
|
18
|
-
|
19
|
-
Otherwise you will need to choose a data push transport. The following guides add the additional configuration
|
20
|
-
information needed to get two way push communications back to the clients.
|
21
|
-
|
22
|
-
The easiest way to setup client push is to use the Pusher-Fake gem. Get started with this [guide.](docs/pusher_faker_quickstart.md)
|
23
|
-
|
24
|
-
If you are already using Pusher follow this [guide.](docs/pusher_quickstart.md)
|
25
|
-
|
26
|
-
If you are on Rails 5 already, and want to try ActionCable use this [guide.](docs/action_cable_quickstart.md)
|
27
|
-
|
28
|
-
All of the above use websockets. For ultimate simplicity use Polling as explained [here.](docs/simple_poller_quickstart.md)
|
29
|
-
|
30
16
|
## Overview
|
31
17
|
|
32
18
|
+ HyperMesh is built on top of HyperReact.
|
33
19
|
+ HyperReact is a Ruby DSL (Domain Specific Language) to build [React.js](https://facebook.github.io/react/) UI components in Ruby. As data changes on the client (either from user interactions or external events) HyperReact re-draws whatever parts of the display is needed.
|
34
|
-
+ HyperMesh provides a [flux dispatcher and data store](https://facebook.github.io/flux/docs/overview.html) backed by [Rails Active Record models](http://guides.rubyonrails.org/active_record_basics.html).
|
35
|
-
|
20
|
+
+ HyperMesh provides a [flux dispatcher and data store](https://facebook.github.io/flux/docs/overview.html) backed by [Rails Active Record models](http://guides.rubyonrails.org/active_record_basics.html).
|
21
|
+
You access your model data in your HyperReact components just like you would on the server or in an ERB or HAML view file.
|
22
|
+
+ If an optional push transport is connected HyperMesh broadcasts any changes made to your ActiveRecord models as they are persisted on the server.
|
36
23
|
|
37
24
|
For example consider a simple model called `Dictionary` which might be part of Wiktionary type app.
|
38
25
|
|
@@ -55,22 +42,18 @@ class WordOfTheDay < React::Component::Base
|
|
55
42
|
|
56
43
|
def pick_entry!
|
57
44
|
# pick a random word and assign the selected record to entry
|
58
|
-
|
59
45
|
@entry = Dictionary.defined.all[rand(Dictionary.defined.count)]
|
60
46
|
force_update! # redraw our component when the word changes
|
61
|
-
|
62
47
|
# Notice that we use standard ActiveRecord constructs to select our
|
63
48
|
# random entry value
|
64
49
|
end
|
65
50
|
|
66
|
-
#
|
67
|
-
|
51
|
+
# pick an initial entry before we mount our component...
|
68
52
|
before_mount :pick_entry
|
69
53
|
|
70
54
|
# Again in our render block we use the standard ActiveRecord API, such
|
71
|
-
# as the 'defined' scope, and the 'word', 'pronunciation',
|
72
|
-
# attribute getters.
|
73
|
-
|
55
|
+
# as the 'defined' scope, and the 'word', 'pronunciation', and
|
56
|
+
# 'definition' attribute getters.
|
74
57
|
render(DIV) do
|
75
58
|
DIV { "total definitions: #{Dictionary.defined.count}" }
|
76
59
|
DIV do
|
@@ -82,197 +65,66 @@ class WordOfTheDay < React::Component::Base
|
|
82
65
|
end
|
83
66
|
```
|
84
67
|
|
68
|
+
## Basic Installation and Setup
|
85
69
|
|
70
|
+
The easiest way to install is to use the `hyper-rails` gem.
|
86
71
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
HyperMesh also adds some features to the `ActiveRecord` `scope` method to manage scopes updates. Details [here.](docs/client_side_scoping.md)
|
92
|
-
|
93
|
-
## Authorization
|
94
|
-
|
95
|
-
Each application defines a number of *channels* and *authorization policies* for those channels and the data sent over the channels.
|
96
|
-
|
97
|
-
Policies are defined with *Policy* classes. These are similar and compatible with [Pundit](https://github.com/elabs/pundit) but
|
98
|
-
you do not need to use the pundit gem (but can if you want.)
|
99
|
-
|
100
|
-
Examples:
|
101
|
-
|
102
|
-
```ruby
|
103
|
-
class ApplicationPolicy
|
104
|
-
# define policies for the Application
|
105
|
-
|
106
|
-
# all clients can connect to the Application
|
107
|
-
always_allow_connection
|
108
|
-
end
|
109
|
-
|
110
|
-
class ProductionCenterPolicy
|
111
|
-
# define policies for the ProductionCenter model
|
112
|
-
|
113
|
-
# any time a ProductionCenter model is updated
|
114
|
-
# broadcast the total_jobs_shipped attribute over the
|
115
|
-
# application channel (i.e. this is public data anybody can see)
|
116
|
-
regulate_broadcast do |policy|
|
117
|
-
policy.send_only(:total_jobs_shipped).to(Application)
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
class UserPolicy
|
122
|
-
# define policies for the User channel and Model
|
72
|
+
1. Add `gem 'hyper-rails'` to your Rails `Gemfile` development section.
|
73
|
+
2. Install the Gem: `bundle install`
|
74
|
+
3. Run the generator: `bundle exec rails g hyperloop:install --hyper-mesh` (or use `--all` to install all hyperloop gems)
|
75
|
+
4. Update the bundle: `bundle update`
|
123
76
|
|
124
|
-
|
125
|
-
regulate_instance_connection { self }
|
126
|
-
|
127
|
-
# users can see all but one field of their own data
|
128
|
-
regulate_broadcast do |policy|
|
129
|
-
policy.send_all_but(:gross_margin_contribution).to(self)
|
130
|
-
end
|
131
|
-
end
|
132
|
-
```
|
77
|
+
You will find a `public` folder has been added to the `app/models` folder. To access a model on the client, move it into the public directory. If you are on Rails 5, you will also need to move the `application_record.rb` into the public directory.
|
133
78
|
|
134
|
-
|
79
|
+
You will also find an `app/policies` folder with a simple access policy suited for development. Policies are how you will provide detailed access control to to your public models. More details [here](/docs/authorization-policies.md).
|
135
80
|
|
136
|
-
|
81
|
+
Once you have run the hyperloop installer you can move models to the `app/models/public` directory and they will be accessible on both the server and client.
|
137
82
|
|
138
|
-
|
83
|
+
## Setting up the Push Transport
|
139
84
|
|
140
|
-
|
85
|
+
To have changes to your models on the server broadcast to authorized clients, add a HyperMesh initializer file and specify a transport. For example to setup a simple polled transport add this file:
|
141
86
|
|
142
87
|
```ruby
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
And then execute:
|
147
|
-
|
148
|
-
$ bundle install
|
149
|
-
|
150
|
-
Also you must `require 'hyper-tracemesh'` from your client side code. The easiest way is to
|
151
|
-
find the `require 'reactive-record'` line (typically in `components.rb`) and replace it with
|
152
|
-
`require 'HyperMesh'`.
|
153
|
-
|
154
|
-
## Configuration
|
155
|
-
|
156
|
-
Add an initializer like this:
|
157
|
-
|
158
|
-
```ruby
|
159
|
-
# for rails this would go in: config/initializers/HyperMesh.rb
|
160
|
-
HyperMesh.configuration do |config|
|
161
|
-
config.transport = :simple_poller # or :none, action_cable, :pusher - see below)
|
162
|
-
end
|
163
|
-
# for a minimal setup you will need to define at least one channel, which you can do
|
164
|
-
# in the same file as your initializer.
|
165
|
-
# Normally you would put these policies in the app/policies/ directory
|
166
|
-
class ApplicationPolicy
|
167
|
-
# allow all clients to connect to the Application channel
|
168
|
-
regulate_connection { true } # or always_allow_connection for short
|
169
|
-
# broadcast all model changes over the Application channel *DANGEROUS*
|
170
|
-
regulate_all_broadcasts { |policy| policy.send_all }
|
88
|
+
# config/initializers/hyper_mesh.rb
|
89
|
+
HyperMesh.configuration |config|
|
90
|
+
config.transport = :simple_poller
|
171
91
|
end
|
172
92
|
```
|
173
93
|
|
174
|
-
|
94
|
+
After restarting, and reloading your browsers you will see changes broadcast to the clients. You can also play with this by firing up a rails console, and creating, changing or destroying models at the console.
|
175
95
|
|
176
|
-
|
177
|
-
|
178
|
-
```ruby
|
179
|
-
#config/initializers/HyperMesh.rb
|
180
|
-
HyperMesh.configuration do |config|
|
181
|
-
config.transport = :action_cable
|
182
|
-
end
|
183
|
-
```
|
96
|
+
For setting up the other possible transports following one of these guides:
|
184
97
|
|
185
|
-
|
98
|
+
The easiest way to setup a true push transport is to use the Pusher-Fake gem. Get started with this [guide.](docs/pusher_faker_quickstart.md)
|
186
99
|
|
187
|
-
|
188
|
-
//application.js
|
189
|
-
...
|
190
|
-
//= require action_cable
|
191
|
-
...
|
192
|
-
```
|
100
|
+
or if you are already using Pusher follow this [guide.](docs/pusher_quickstart.md)
|
193
101
|
|
194
|
-
|
102
|
+
or if you are on Rails 5, and want to use ActionCable follow this [guide.](docs/action_cable_quickstart.md)
|
195
103
|
|
196
|
-
|
104
|
+
## Basic Configuration
|
197
105
|
|
198
|
-
|
106
|
+
For complete details on configuration settings go [here](/docs/configuration_details.md)
|
199
107
|
|
200
|
-
|
108
|
+
## ActiveRecord API
|
201
109
|
|
202
|
-
|
203
|
-
# typically config/initializers/HyperMesh.rb
|
204
|
-
HyperMesh.configuration do |config|
|
205
|
-
config.transport = :pusher
|
206
|
-
config.opts = {
|
207
|
-
app_id: '2xxxx2',
|
208
|
-
key: 'dxxxxxxxxxxxxxxxxxx9',
|
209
|
-
secret: '2xxxxxxxxxxxxxxxxxx2',
|
210
|
-
encrypted: false # optional defaults to true
|
211
|
-
}
|
212
|
-
config.channel_prefix = 'syncromesh' # or any other string you want
|
213
|
-
end
|
214
|
-
```
|
110
|
+
HyperMesh uses a large subset of the ActiveRecord API modified only when necessary to accommodate the asynchronous nature of the client.
|
215
111
|
|
216
|
-
|
112
|
+
See this [guide](/docs/activerecord_api.md) for details.
|
217
113
|
|
218
|
-
|
219
|
-
add `gem 'pusher-fake'` to the development and/or test section of your gem file. Then setup your config file:
|
114
|
+
**Warning** currently the `attributes` method is supported, but please do not use it as some details of the semantics will be changing in an upcoming release. Instead of `foo.attributes[:xyz]` use `foo.send('xyz')` for now.
|
220
115
|
|
221
|
-
|
222
|
-
# typically config/initializers/HyperMesh.rb
|
223
|
-
# or you can do a similar setup in your tests (see this gem's specs)
|
224
|
-
require 'pusher'
|
225
|
-
require 'pusher-fake'
|
226
|
-
# The app_id, key, and secret need to be assigned directly to Pusher
|
227
|
-
# so PusherFake will work.
|
228
|
-
Pusher.app_id = "MY_TEST_ID" # you use the real or fake values
|
229
|
-
Pusher.key = "MY_TEST_KEY"
|
230
|
-
Pusher.secret = "MY_TEST_SECRET"
|
231
|
-
# The next line actually starts the pusher-fake server (see the Pusher-Fake readme for details.)
|
232
|
-
require 'pusher-fake/support/base' # if using pusher with rspec change this to pusher-fake/support/rspec
|
233
|
-
# now copy over the credentials, and merge with PusherFake's config details
|
234
|
-
HyperMesh.configuration do |config|
|
235
|
-
config.transport = :pusher
|
236
|
-
config.channel_prefix = "HyperMesh"
|
237
|
-
config.opts = {
|
238
|
-
app_id: Pusher.app_id,
|
239
|
-
key: Pusher.key,
|
240
|
-
secret: Pusher.secret
|
241
|
-
}.merge(PusherFake.configuration.web_options)
|
242
|
-
end
|
243
|
-
```
|
116
|
+
## Client Side Scoping
|
244
117
|
|
245
|
-
|
118
|
+
By default scopes will be recalculated on the server. To offload this to the client HyperMesh adds some features to the `ActiveRecord` `scope` method. Details [here.](docs/client_side_scoping.md)
|
246
119
|
|
247
|
-
|
248
|
-
```ruby
|
249
|
-
HyperMesh.configuration do |config|
|
250
|
-
config.transport = :simple_poller
|
251
|
-
config.channel_prefix = "HyperMesh"
|
252
|
-
config.opts = {
|
253
|
-
seconds_between_poll: 5, # default is 0.5 you may need to increase if testing with Selenium
|
254
|
-
seconds_polled_data_will_be_retained: 1.hour # clears channel data after this time, default is 5 minutes
|
255
|
-
}
|
256
|
-
end
|
257
|
-
```
|
258
|
-
|
259
|
-
## The Cache store
|
260
|
-
|
261
|
-
HyperMesh uses the rails cache to keep track of what connections are alive in a transport independent fashion. Rails 5 by default will have caching off in development mode.
|
120
|
+
## Authorization
|
262
121
|
|
263
|
-
|
122
|
+
Each application defines a number of *channels* and *authorization policies* for those channels and the data sent over the channels.
|
264
123
|
|
265
|
-
|
266
|
-
|
124
|
+
Policies are defined with *Policy* classes. These are similar and compatible with [Pundit](https://github.com/elabs/pundit) but
|
125
|
+
you do not need to use the pundit gem (but can if you want.)
|
267
126
|
|
268
|
-
|
269
|
-
# config/development.rb
|
270
|
-
Rails.application.configure do
|
271
|
-
...
|
272
|
-
config.cache_store = :file_store, './rails_cache_dir'
|
273
|
-
...
|
274
|
-
end
|
275
|
-
```
|
127
|
+
For complete details see [Authorization Policies](docs/authorization-policies.md)
|
276
128
|
|
277
129
|
## Common Errors
|
278
130
|
|
@@ -283,7 +135,7 @@ By default HyperMesh will look for a `ApplicationPolicy` class.
|
|
283
135
|
- Wrong version of pusher-fake (pusher-fake/base vs. pusher-fake/rspec)
|
284
136
|
See the Pusher-Fake gem repo for details.
|
285
137
|
|
286
|
-
- Forgetting to add require pusher in application.js file
|
138
|
+
- Forgetting to add `require pusher` in application.js file
|
287
139
|
this results in an error like this:
|
288
140
|
```text
|
289
141
|
Exception raised while rendering #<TopLevelRailsComponent:0x53e>
|
@@ -296,10 +148,6 @@ You must explicitly allow changes to the models to be made by the client. If you
|
|
296
148
|
see 500 responses from the server when you try to update. To open all access do this in
|
297
149
|
your application policy: `allow_change(to: :all, on: [:create, :update, :destroy]) { true }`
|
298
150
|
|
299
|
-
- `Cannot Run HyperMesh with cache_store == :null_store`
|
300
|
-
You will get this error on boot if you are trying to use the :null cache.
|
301
|
-
See notes above on why you cannot use the :null cache store.
|
302
|
-
|
303
151
|
- Cannot connect to real pusher account:
|
304
152
|
If you are trying to use a real pusher account (not pusher-fake) but see errors like this
|
305
153
|
```text
|
@@ -315,6 +163,16 @@ HyperMesh will always try to use pusher-fake if it sees the gem included. Remov
|
|
315
163
|
- Attributes are not being converted from strings, or do not have their default values
|
316
164
|
Eager loading is probably turned off. HyperMesh needs to eager load `models/public` so it can find all the column information for all public models.
|
317
165
|
|
166
|
+
- When starting rails you get a message on the rails console `couldn't find file 'browser'`
|
167
|
+
Hyper-React v0.10.0 removed the dependency on opal-browser. You will have to add the 'opal-browser' gem to your Gemfile.
|
168
|
+
|
169
|
+
- On page load you get a message yacking about super class mismatch for `DummyValue`
|
170
|
+
You are still have the old `reactive-record` gem in your Gemfile, remove it from your gemfile and your components.rb manifest.
|
171
|
+
|
172
|
+
- On page load you get a message yacking about no method `session` for `nil`
|
173
|
+
You are still referencing the old reactive-ruby or reactrb gems either directly or indirectly though a gem like reactrb-router. Replace any gems like
|
174
|
+
`reactrb-router` with `hyper-router`. You can also just remove `reactrb`, as `hyper-react` will be included by the `hyper-mesh` gem.
|
175
|
+
|
318
176
|
## Debugging
|
319
177
|
|
320
178
|
Sometimes you need to figure out what connections are available, or what attributes are readable etc.
|
@@ -362,14 +220,13 @@ You can of course simulate server side changes to your models through this conso
|
|
362
220
|
## Development
|
363
221
|
|
364
222
|
The original `ReactiveRecord` specs were written in opal-rspec. These are being migrated to
|
365
|
-
use server rspec with isomorphic helpers. There are about
|
366
|
-
these you
|
223
|
+
use server rspec with isomorphic helpers. There are about 170 of the original tests left and to run these you
|
367
224
|
|
368
225
|
1. cd to `reactive_record_spec/test_app`
|
369
226
|
2. do a bundle install/update as needed,
|
370
|
-
3. rake db:reset db:test:prepare
|
227
|
+
3. `rake db:reset db:test:prepare`,
|
371
228
|
4. start the server: `bundle exec rails s`,
|
372
|
-
5. then visit localhost/spec-opal
|
229
|
+
5. then visit `localhost:3000/spec-opal`.
|
373
230
|
|
374
231
|
If you want to help **PLEASE** consider spending an hour and migrate a spec file to the new format. You can
|
375
232
|
find examples by looking in the `spec/reactive_record/` directory and matching to the original file in
|
@@ -385,12 +242,10 @@ bundle exec rspec spec
|
|
385
242
|
|
386
243
|
You can run the specs in firefox by adding `DRIVER=ff` (best for debugging.) You can add `SHOW_LOGS=true` if running in poltergeist (the default) to see what is going on, but ff is a lot better for debug.
|
387
244
|
|
388
|
-
|
389
245
|
## Contributing
|
390
246
|
|
391
247
|
Bug reports and pull requests are welcome on GitHub at https://github.com/reactive-ruby/HyperMesh. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
392
248
|
|
393
|
-
|
394
249
|
## License
|
395
250
|
|
396
251
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/config/routes.rb
CHANGED
@@ -1,29 +1,21 @@
|
|
1
1
|
### Action Cable Quickstart
|
2
2
|
|
3
|
-
Action Cable is production ready transport built into Rails 5.
|
3
|
+
Action Cable is a production ready transport built into Rails 5.
|
4
4
|
|
5
5
|
#### 1 Get Rails 5
|
6
6
|
|
7
7
|
You need to be on rails 5 to use ActionCable. Make sure you upgrade to rails 5 first.
|
8
8
|
|
9
|
-
#### 2 Add
|
9
|
+
#### 2 Add HyperLoop gems
|
10
10
|
|
11
|
-
If you have not already installed the `
|
11
|
+
If you have not already installed the `hyper-react` and `hyper-mesh` gems, then do so now using the [hyper-rails](https://github.com/ruby-hyperloop/hyper-rails) gem.
|
12
12
|
|
13
|
-
- add `gem '
|
13
|
+
- add `gem 'hyper-rails'` to your gem file (in the development section)
|
14
14
|
- run `bundle install`
|
15
|
-
- run `rails g
|
15
|
+
- run `rails g hyperloop:install --all` (make sure to use the --all option)
|
16
16
|
- run `bundle update`
|
17
17
|
|
18
|
-
#### 3
|
19
|
-
|
20
|
-
- replace the `'reactive-record'` and `'reactrb'` gems with
|
21
|
-
`gem 'hyper-mesh', git: 'https://github.com/ruby-hyperloop/hyper-mesh'`
|
22
|
-
**note:** you must remove `gem 'reactive-record'`
|
23
|
-
- then `bundle install`
|
24
|
-
- and in `app/views/components.rb` replace `require 'reactive-record'` with `require 'hyper-mesh'`
|
25
|
-
|
26
|
-
#### 4 Set the transport
|
18
|
+
#### 3 Set the transport
|
27
19
|
|
28
20
|
Once you have HyperMesh installed then add this initializer:
|
29
21
|
```ruby
|
@@ -33,28 +25,13 @@ HyperMesh.configuration do |config|
|
|
33
25
|
end
|
34
26
|
```
|
35
27
|
|
36
|
-
####
|
37
|
-
|
38
|
-
To start just open everything up by adding a policies directory and defining a policy file like this:
|
39
|
-
|
40
|
-
```ruby
|
41
|
-
# app/policies/application_policy.rb
|
42
|
-
class ApplicationPolicy
|
43
|
-
always_allow_connection
|
44
|
-
regulate_all_broadcasts { |policy| policy.send_all }
|
45
|
-
allow_change(to: :all, on: [:create, :update, :destroy]) { true }
|
46
|
-
end
|
47
|
-
```
|
48
|
-
|
49
|
-
#### 6 Setup ActionCable
|
28
|
+
#### 4 Setup ActionCable
|
50
29
|
|
51
30
|
If you are already using ActionCable in your app that is fine, as HyperMesh will not interfere with your existing connections.
|
52
31
|
|
53
32
|
Otherwise go through the following steps to setup ActionCable.
|
54
33
|
|
55
|
-
#####
|
56
|
-
|
57
|
-
Include the `action_cable` js file in your assets
|
34
|
+
##### Make sure the `action_cable` js file in your assets
|
58
35
|
|
59
36
|
```javascript
|
60
37
|
//app/assets/javascripts/application.js
|
@@ -63,7 +40,7 @@ Include the `action_cable` js file in your assets
|
|
63
40
|
Opal.load('components');
|
64
41
|
```
|
65
42
|
|
66
|
-
#####
|
43
|
+
##### Make sure you have a cable.yml file
|
67
44
|
|
68
45
|
```yml
|
69
46
|
# config/cable.yml
|
@@ -78,7 +55,7 @@ production:
|
|
78
55
|
url: redis://localhost:6379/1
|
79
56
|
```
|
80
57
|
|
81
|
-
#####
|
58
|
+
##### Set allowed request origins (optional)
|
82
59
|
|
83
60
|
By default action cable will only allow connections from localhost:3000 in development. If you are going to something other than localhost:3000 you need to add something like this to your config:
|
84
61
|
|
@@ -89,7 +66,7 @@ Rails.application.configure do
|
|
89
66
|
end
|
90
67
|
```
|
91
68
|
|
92
|
-
####
|
69
|
+
#### 5 Try It Out
|
93
70
|
|
94
71
|
If you don't already have a model to play with, add one now:
|
95
72
|
|
@@ -101,7 +78,7 @@ Whatever model(s) you will plan to access on the client need to moved to the `ap
|
|
101
78
|
|
102
79
|
**Important** in rails 5 there is also a base `ApplicationRecord` class, that all other models are built from. This class must be moved to the public directory as well.
|
103
80
|
|
104
|
-
If you don't already have a simple component to play with, here is a simple one (make sure you
|
81
|
+
If you don't already have a simple component to play with, here is a simple one (make sure you added the Word model):
|
105
82
|
|
106
83
|
```ruby
|
107
84
|
# app/views/components/app.rb
|
@@ -148,4 +125,4 @@ Fire up rails with `bundle exec rails s` and open your app in a couple of browse
|
|
148
125
|
|
149
126
|
You can also fire up a rails console, and then for example do a `Word.new(text: "Hello").save` and again see any browsers updating.
|
150
127
|
|
151
|
-
If you want to go into more details with example check out [words-example](/docs/words-example.md)
|
128
|
+
If you want to go into more details with the example check out [words-example](/docs/words-example.md)
|