Sha256: c6a32b8389b25670028768f5aa3ebb5b5b887d49d883e249c314b34d6db41de0

Contents?: true

Size: 1.38 KB

Versions: 2

Compression:

Stored size: 1.38 KB

Contents

class J7W1ApplicationDevice < ActiveRecord::Base
  self.table_name = 'j7w1_application_devices'

  belongs_to :owner, polymorphic: true

<%- if options['async_engine'] -%>
  after_create :create_device_endpoint_async
  after_destroy :destroy_device_endpoint_async
<%- else -%>
  after_create :create_device_endpoint
  after_destroy :destroy_device_endpoint
<%- end -%>

  scope :identified, -> identifier { where(device_identifier: identifier) }
  scope :on_platform, -> platform { where(platform: J7W1::Util.normalize_platform(platform)) }

  def push!(options = {})
    J7W1::PushClient.push device_endpoint_arn, platform, *options
  end

  def create_device_endpoint
    device_endpoint_arn = J7W1::PushClient.create_device_endpoint device_identifier, platform_id,
      custom_user_data: "#{owner.class} ##{owner.id}"
    update_attributes! device_endpoint_arn: device_endpoint_arn
  end

  def destroy_device_endpoint
    J7W1::PushClient.destroy_endpoint device_arn
  end

  private
<%- if options['async_engine'] == 'delayed_job' -%>

  def create_device_endpoint_async
    delay.create_device_endpoint
  end

  def destroy_device_endpoint_async
    delay.destroy_device_endpoint
  end
<%- elsif options['async_engine'] == 'sidekiq' -%>

  def create_device_endpoint_async
    J7W1Worker.perform_async id
  end

  def destroy_device_endpoint_async
    J7W1Worker.perform_async id
  end
<%- end -%>
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
j7w1-0.0.7 lib/generators/j7_w1/model/templates/j7_w1_application_device.rb.erb
j7w1-0.0.6 lib/generators/j7_w1/model/templates/j7_w1_application_device.rb.erb