Sha256: cf8964fa4417f58db0fc74edcdb4378f82de05726d3cceffc5a4e28722e1f255

Contents?: true

Size: 863 Bytes

Versions: 5

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 40, :push_token
      end

      private

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rack-passbook-0.1.1 ./lib/rack/passbook/models/registration.rb
rack-passbook-0.1.0 ./lib/rack/passbook/models/registration.rb
rack-passbook-0.0.3 ./lib/rack/passbook/models/registration.rb
rack-passbook-0.0.2 ./lib/rack/passbook/models/registration.rb
rack-passbook-0.0.1 ./lib/rack/passbook/models/registration.rb