Class: Rpush::Client::ActiveModel::Fcm::NotificationKeysInAllowedListValidator

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

Instance Method Summary collapse

Instance Method Details

#validate(record) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/rpush/client/active_model/fcm/notification_keys_in_allowed_list_validator.rb', line 6

def validate(record)
  return unless record.notification

  allowed_keys = Notification::ROOT_NOTIFICATION_KEYS + Notification::ANDROID_NOTIFICATION_KEYS
  invalid_keys = record.notification.keys - allowed_keys

  return if invalid_keys.empty?

  record.errors.add(:notification, "contains invalid keys: #{invalid_keys.join(', ')}")
end