Sha256: 286b65ef4a6634dfd9922cc185412e122e4ea6ba1d9dcdad1bcc69e0a095d2d8

Contents?: true

Size: 1.21 KB

Versions: 4

Compression:

Stored size: 1.21 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,
      :sharing_prohibited,
      :max_distance,
      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

4 entries across 4 versions & 1 rubygems

Version Path
passkit-0.5.4 app/models/passkit/pass.rb
passkit-0.5.3 app/models/passkit/pass.rb
passkit-0.5.2 app/models/passkit/pass.rb
passkit-0.5.1 app/models/passkit/pass.rb