Class: OfflineBroadcaster::Config

Inherits:
Struct
  • Object
show all
Defined in:
lib/offline_broadcaster/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#adapterObject

Returns the value of attribute adapter

Returns:

  • (Object)

    the current value of adapter



3
4
5
# File 'lib/offline_broadcaster/config.rb', line 3

def adapter
  @adapter
end

#modelObject

Returns the value of attribute model

Returns:

  • (Object)

    the current value of model



3
4
5
# File 'lib/offline_broadcaster/config.rb', line 3

def model
  @model
end

#online_attributeObject

Returns the value of attribute online_attribute

Returns:

  • (Object)

    the current value of online_attribute



3
4
5
# File 'lib/offline_broadcaster/config.rb', line 3

def online_attribute
  @online_attribute
end

Instance Method Details

#setup_callbacksObject

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