Sha256: 6c9158d1bccbc85464171b73b79b6d91511e48e5f9b056cc1b72abe48bfb9125

Contents?: true

Size: 1.06 KB

Versions: 9

Compression:

Stored size: 1.06 KB

Contents

module Rpush
  module Client
    module ActiveModel
      module Webpush
        module App

          class VapidKeypairValidator < ::ActiveModel::Validator
            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
          end

          def self.included(base)
            base.class_eval do
              alias_attribute :vapid_keypair, :certificate
              validates :vapid_keypair, presence: true
              validates_with VapidKeypairValidator
            end
          end

          def service_name
            'webpush'
          end

          def vapid
            @vapid ||= JSON.parse(vapid_keypair).symbolize_keys
          end

        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rpush-9.1.0 lib/rpush/client/active_model/webpush/app.rb
rpush-9.0.0 lib/rpush/client/active_model/webpush/app.rb
rpush-8.0.0 lib/rpush/client/active_model/webpush/app.rb
rpush-7.0.1 lib/rpush/client/active_model/webpush/app.rb
rpush-7.0.0 lib/rpush/client/active_model/webpush/app.rb
rpush-6.0.1 lib/rpush/client/active_model/webpush/app.rb
rpush-6.0.0 lib/rpush/client/active_model/webpush/app.rb
rpush-5.4.0 lib/rpush/client/active_model/webpush/app.rb
rpush-5.3.0 lib/rpush/client/active_model/webpush/app.rb