Sha256: 0add75a7917f43f87cd81a5bcaf482cd75cf6fcdb21f91654eeb6648d0954108

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

module J7W1
  module ActiveRecordExt
    def self.included(base)
      base.extend ClassMethods
    end

    module ClassMethods
      private
      def application_device_owner
        include InstanceMethods

        has_many :application_devices, class_name: 'J7W1ApplicationDevice'
      end
    end

    module InstanceMethods
      def add_device(device_identifier, platform)
        device =
          J7W1ApplicationDevice.identified(device_identifier).on_platform(J7W1::Util.normalize_platform(platform)).
          first_or_initialize
        device.endpoint_arn = nil
        device.owner = self
        device.save!
      end

      def remove_device(device_identifier, platform)
        devices.where(device_identifier: device_identifier, platform: platform).
          destroy_all
      end

      def push!(options = {})
        sns_client = self.create_sns_client
        aplication_devices.each do |device|
          device.push! options.tap{|o|o.merge! sns_client: sns_client}
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
j7w1-0.0.6 lib/j7_w1/active_record_ext.rb
j7w1-0.0.5 lib/j7_w1/active_record_ext.rb