Sha256: 5f82a51a7313ce2ba66ff5dfe61cb2ffa08e4ce3b2b225bca9a74254029a8a70

Contents?: true

Size: 834 Bytes

Versions: 4

Compression:

Stored size: 834 Bytes

Contents

module Yodeler
  class Notification < ActiveRecord::Base
    validates_presence_of :subscription
    validates_presence_of :event
        
    belongs_to :event, class_name: "Yodeler::Event", foreign_key: :yodeler_event_id
    belongs_to :subscription, class_name: "Yodeler::Subscription", foreign_key: :yodeler_subscription_id

    delegate :event_type, to: :event
    delegate :subscriber, to: :subscription

    def message
      I18n.t("yodeler.event_types.#{event_type_key}.message", event.payload)
    end

    def name
      I18n.t("yodeler.event_types.#{event_type_key}.name", event.payload)
    end

    def state
      state_enum_value = read_attribute :state
      event_type.class.configuration.states.key(state_enum_value)
    end

    protected
      def event_type_key
        event_type.name.to_sym
      end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
yodeler-0.0.10 lib/yodeler/models/notification.rb
yodeler-0.0.9 lib/yodeler/models/notification.rb
yodeler-0.0.8 lib/yodeler/models/notification.rb
yodeler-0.0.7 lib/yodeler/models/notification.rb