Sha256: 3bb69e7eab038dbeca09ee5cd5a7faf27fa67df9db24a2a1c457bec0d899398e

Contents?: true

Size: 863 Bytes

Versions: 1

Compression:

Stored size: 863 Bytes

Contents

module Rack
  class Passbook
    class Registration < Sequel::Model
      plugin :json_serializer, naked: true, except: :id 
      plugin :validation_helpers
      plugin :timestamps, force: true, update_on_create: true
      plugin :schema

      self.dataset = :passbook_registrations
      self.strict_param_setting = false
      self.raise_on_save_failure = false

      def before_validation
        normalize_push_token! if self.push_token
      end

      def validate
        super

        validates_presence :device_library_identifier
        validates_unique [:device_library_identifier, :pass_id]
        validates_format /[[:xdigit:]]+/, :push_token
        validates_exact_length 64, :push_token
      end

      private

      def normalize_push_token!
        self.push_token = self.push_token.strip.gsub(/[<\s>]/, '')
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rack-passbook-0.2.0 ./lib/rack/passbook/models/registration.rb