Sha256: 8b4ae99871479a00e0b963861f2595a4d1a0ea6970a98f2c8ab3ba95dccef7f3
Contents?: true
Size: 1 KB
Versions: 3
Compression:
Stored size: 1 KB
Contents
module NulogyMessageBusProducer # This model saves all subscriptions to external systems. # An external system can subscribe to events and specify the shape of data it would like to receive for the event. class PublicSubscription < ApplicationRecord self.table_name = :message_bus_subscriptions # Run our validator with familar syntax in this model class ValidForSchemaValidator < ActiveModel::EachValidator def validate_each(record, attribute, _value) return if record.schema_key.blank? || record.query.blank? validator = NulogyMessageBusProducer::SubscriberGraphqlSchemaValidator.new validator.validate(record) validator.errors.each { |e| record.errors.add(attribute, e) } end end validates :schema_key, :event_type, presence: true validates :query, presence: true, valid_for_schema: true def self.create_or_update(attrs) find_or_initialize_by(id: attrs[:id]).tap do |model| model.update!(attrs) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems