Class: Rpush::Client::ActiveModel::Webpush::Notification::RegistrationValidator

Inherits:
ActiveModel::Validator
  • Object
show all
Defined in:
lib/rpush/client/active_model/webpush/notification.rb

Constant Summary collapse

KEYS =
%i[ endpoint keys ].freeze

Instance Method Summary collapse

Instance Method Details

#validate(record) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rpush/client/active_model/webpush/notification.rb', line 9

def validate(record)
  return if record.registration_ids.blank?
  return if record.registration_ids.size > 1
  reg = record.registration_ids.first
  unless reg.is_a?(Hash) &&
      (KEYS-reg.keys).empty? &&
      reg[:endpoint].is_a?(String) &&
      reg[:keys].is_a?(Hash)
    record.errors.add(:base, 'Registration must have :endpoint (String) and :keys (Hash) keys')
  end
end