Sha256: 2eff4ce361660f561e02a3b7e2d5eb79ff0192de8b81ae3e7a3e21946c0c09f1

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 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,
      :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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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