Class: Pushable::ConsolePush

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
app/models/pushable/console_push.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ ConsolePush

Returns a new instance of ConsolePush.



9
10
11
12
# File 'app/models/pushable/console_push.rb', line 9

def initialize(attributes = {})
  super
  @sent_count = 0
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



5
6
7
# File 'app/models/pushable/console_push.rb', line 5

def data
  @data
end

#device_tokenObject

Returns the value of attribute device_token.



5
6
7
# File 'app/models/pushable/console_push.rb', line 5

def device_token
  @device_token
end

#klassObject

Returns the value of attribute klass.



5
6
7
# File 'app/models/pushable/console_push.rb', line 5

def klass
  @klass
end

#sent_countObject

Returns the value of attribute sent_count.



5
6
7
# File 'app/models/pushable/console_push.rb', line 5

def sent_count
  @sent_count
end

Instance Method Details

#deliverObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/models/pushable/console_push.rb', line 14

def deliver
  data.each do |name, info|
    setter = "#{name}="
    if message.respond_to?(setter)
      value = info['value']
      value = value.to_i if info['type'] == 'integer'
      message.send setter, value
    end
  end

  devices.each do |device|
    if recipient = device.pushable
      response = message.send_to recipient
      self.sent_count += 1
    end
  end
end