Class: Rpush::Client::ActiveModel::Webpush::App::VapidKeypairValidator

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

Instance Method Summary collapse

Instance Method Details

#validate(record) ⇒ Object



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

def validate(record)
  return if record.vapid_keypair.blank?
  keypair = record.vapid
  %i[ subject public_key private_key ].each do |key|
    unless keypair.key?(key)
      record.errors.add(:vapid_keypair, "must have a #{key} entry")
    end
  end
rescue
  record.errors.add(:vapid_keypair, 'must be valid JSON')
end