Sha256: 55676262300305aa68397205e97a187780e74d74b5aeb968e252d3b76ac9f9f8

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

module Passkit
  class Pass < ActiveRecord::Base
    validates_uniqueness_of :serial_number
    validates_presence_of :klass

    belongs_to :generator, polymorphic: true, optional: true
    has_many :registrations, foreign_key: :passkit_pass_id
    has_many :devices, through: :registrations

    delegate :file_name,
      :pass_path,
      :language,
      :format_version,
      :apple_team_identifier,
      :foreground_color,
      :background_color,
      :label_color,
      :web_service_url,
      :barcode,
      :voided,
      :organization_name,
      :description,
      :logo_text,
      :locations,
      :pass_type_identifier,
      :pass_type,
      :header_fields,
      :primary_fields,
      :secondary_fields,
      :auxiliary_fields,
      :back_fields,
      to: :instance

    before_validation on: :create do
      self.authentication_token ||= SecureRandom.hex
      loop do
        self.serial_number = SecureRandom.uuid
        break unless self.class.exists?(serial_number: serial_number)
      end
    end

    def instance
      @instance ||= klass.constantize.new(generator)
    end

    def last_update
      instance.last_update || updated_at
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
passkit-0.5.0 app/models/passkit/pass.rb