Module: ActionCableNotifications::Callbacks::ClassMethods
- Defined in:
- lib/action_cable_notifications/callbacks.rb
Instance Method Summary collapse
-
#broadcast_notifications_from(broadcasting, options = nil) ⇒ Object
Sets or removes notificacions options for Active Record model.
-
#notify_initial(broadcasting) ⇒ Hash
Retrieves initial values to be sent to clients upon subscription.
-
#scoped_collection(scope = :all) ⇒ ActiveRecordRelation
Returns collection scoped as specified in parameters.
Instance Method Details
#broadcast_notifications_from(broadcasting, options = nil) ⇒ Object
Sets or removes notificacions options for Active Record model
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/action_cable_notifications/callbacks.rb', line 24 def broadcast_notifications_from ( broadcasting, = nil ) if .present? # Default options = { actions: [:create, :update, :destroy], scope: :all # Default collection scope }.merge() self.ActionCableNotificationsOptions[broadcasting.to_sym] = else self.ActionCableNotificationsOptions.except! broadcasting.to_sym end end |
#notify_initial(broadcasting) ⇒ Hash
Retrieves initial values to be sent to clients upon subscription
collection: self.model_name.collection,
msg: 'add_collection',
data: self.scoped_collection([:scope])
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/action_cable_notifications/callbacks.rb', line 61 def notify_initial ( broadcasting ) = self.ActionCableNotificationsOptions[broadcasting.to_sym] if .present? { collection: self.model_name.collection, msg: 'add_collection', data: self.scoped_collection([:scope]) } end end |
#scoped_collection(scope = :all) ⇒ ActiveRecordRelation
Returns collection scoped as specified in parameters.
example: [[:limit, 5], [:order, :id]]
46 47 48 |
# File 'lib/action_cable_notifications/callbacks.rb', line 46 def scoped_collection ( scope=:all ) Array(scope).inject(self) {|o, a| o.try(*a)} end |