Class: OfflineBroadcaster::Config
- Inherits:
-
Struct
- Object
- Struct
- OfflineBroadcaster::Config
- Defined in:
- lib/offline_broadcaster/config.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
Returns the value of attribute adapter.
-
#model ⇒ Object
Returns the value of attribute model.
-
#online_attribute ⇒ Object
Returns the value of attribute online_attribute.
Instance Method Summary collapse
-
#setup_callbacks ⇒ Object
Enters into callback if user is online hence, we need to deliver pending records.
Instance Attribute Details
#adapter ⇒ Object
Returns the value of attribute adapter
3 4 5 |
# File 'lib/offline_broadcaster/config.rb', line 3 def adapter @adapter end |
#model ⇒ Object
Returns the value of attribute model
3 4 5 |
# File 'lib/offline_broadcaster/config.rb', line 3 def model @model end |
#online_attribute ⇒ Object
Returns the value of attribute online_attribute
3 4 5 |
# File 'lib/offline_broadcaster/config.rb', line 3 def online_attribute @online_attribute end |
Instance Method Details
#setup_callbacks ⇒ Object
Enters into callback if user is online
hence, we need to deliver pending records.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/offline_broadcaster/config.rb', line 6 def setup_callbacks model.before_save if: -> { send("#{offline_broadcaster_config.online_attribute}_changed?") && send(offline_broadcaster_config.online_attribute) } do adapter = offline_broadcaster_config.adapter self.offline_broadcaster_records.in_batches do |records| records.each do |record| adapter.collect(channel: record.channel, receiver: record.receiver, data: record.data) end records.destroy_all end end end |