create
, update
, and destroy
policies giving (or denying) the acting_user
the ability to do these operations.acting_user
. Read access is initiated when a specific browser tries to read a record attribute, and broadcasts are initiated whenever a model changes.AdminUser
channel shared by all administrators that are logged in.Todo
changes, which is part of team id 123's Todo list, and users 7 and 8 who are members of that team are currently logged in as well as two of the AdminUsers
.Todo
changes we want all the attributes of the Todo
broadcast on team 123's channel, as well on the AdminUser
's channel. Now lets say User 7 sends User 8 a private message, adding a new record to the Message
model. This update should only be sent to user 7 and user 8's private channels, as well as to the AdminUser channel.acting_user
method in our ApplicationController:acting_user
is also used by ReactiveRecord's permission system.User
, an AdminUser
, or a Team
of users. A channel associated with the class itself broadcasts data that is received by any member of that class. A channel associated with an instance is for data that is available only to that specific instance.Policy
added to the end. Policy classes are compatible with Pundit
, and you can add regular pundit policies as well.regulate_class_connection
controls connections to the class channels,regulate_instance_connections
controls connections to instance channels,regulate_broadcast
controls what data will be sent when a model or object changes and,regulate_all_broadcasts
controls what data will be sent of some channels when any model changes.always_allow_connection
is short hand for regulate_class_connection { true }
app/policies
directory. Hyperloop will require all the files in this directory.Hyperloop::PolicyMethods
module in your model. You can then use the regulate_class_connection
, regulate_instance_connections
, regulate_all_broadcasts
and regulate_broadcast
methods directly in the model.regulate_class_connection
takes a block that will execute in the context of the current acting_user (which may be nil), and if the block returns any truthy value, the connection will be made.regulate_instance_connections
likewise takes a block that is executed in the context of the current acting_user. The block may do one of following:id
on the instance.app/hyperloop/models
folder everything will work fine.acting_user
method typically defined in the ApplicationController and would normally pick up the current session user, and return an appropriate object.acting_user
are automatically made on the initial page load. This behavior can be turned off with the auto_connect
option.Hyperloop.connect
method.connect
method takes any number of arguments each of which is either a class, an object, a String or Array.connect
directly to ActiveRecord models:Hyperloop.connect
.acting_user
,regulate_class_connection
method.regulate_class_connection
returns a truthy value then the connection is made,find
of the id passed to get the instance,regulate_instance_connections
is called,Hyperloop.disconnect(channel)
or channel.disconnect!
will disconnect from the channel.regulate_all_broadcasts
method, and for individual objects (typically ActiveRecord models) using the regulate_broadcast
method. A regulate_all_broadcasts
policy is essentially a regulate_broadcast
that will be run for every record that changes in the system.send_all
: send all the attributes of the record.send_only
: send only the listed attributes of the record.send_all_but
: send all the attributes except the ones listed.send...
method is then directed to the set of channels using the to
method:to
method can take any number of arguments:class_eval
thus keeping policy logic out of your models.acting_user
is also defined for the life of the block.admin?
but this is not built into Hyperloop.allow_read
method. Read access is granted if this browser would have the attribute broadcast to it.regulate_connection
regulate_all_broadcasts
regulate_broadcast
send_all
send_all_but
send_only
obj
attr_accessor
s named synchromesh_internal_policy_object
. The above methods call methods of the same name in the appropriate internal policy object.