Class: Rpush::Client::ActiveRecord::Notification

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Rpush::Client::ActiveModel::Notification, MultiJsonHelper
Defined in:
lib/rpush/client/active_record/notification.rb

Instance Method Summary collapse

Methods included from Rpush::Client::ActiveModel::Notification

included, #payload, #payload_data_size

Methods included from MultiJsonHelper

#multi_json_dump, #multi_json_load

Instance Method Details

#dataObject



32
33
34
# File 'lib/rpush/client/active_record/notification.rb', line 32

def data
  multi_json_load(read_attribute(:data)) if read_attribute(:data)
end

#data=(attrs) ⇒ Object



15
16
17
18
19
# File 'lib/rpush/client/active_record/notification.rb', line 15

def data=(attrs)
  return unless attrs
  fail ArgumentError, 'must be a Hash' unless attrs.is_a?(Hash)
  write_attribute(:data, multi_json_dump(attrs.merge(data || {})))
end

#notificationObject



36
37
38
# File 'lib/rpush/client/active_record/notification.rb', line 36

def notification
  multi_json_load(read_attribute(:notification)) if read_attribute(:notification)
end

#notification=(attrs) ⇒ Object



21
22
23
24
25
# File 'lib/rpush/client/active_record/notification.rb', line 21

def notification=(attrs)
  return unless attrs
  fail ArgumentError, 'must be a Hash' unless attrs.is_a?(Hash)
  write_attribute(:notification, multi_json_dump(attrs.merge(data || {})))
end

#registration_ids=(ids) ⇒ Object



27
28
29
30
# File 'lib/rpush/client/active_record/notification.rb', line 27

def registration_ids=(ids)
  ids = [ids] if ids && !ids.is_a?(Array)
  super
end