Class: ActivityNotification::ORM::ActiveRecord::Subscription

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
SubscriptionApi
Defined in:
lib/activity_notification/orm/active_record/subscription.rb

Overview

Subscription model implementation generated by ActivityNotification.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SubscriptionApi

#as_json, convert_time_as_hash, #earliest_order, #earliest_order!, #earliest_subscribed_order, filtered_by_key, filtered_by_options, #key_order, #latest_order, #latest_order!, #latest_subscribed_order, #optional_target_names, #subscribe, #subscribe_to_email, #subscribe_to_optional_target, #subscribing_to_optional_target?, to_optional_target_key, to_optional_target_subscribed_at_key, to_optional_target_unsubscribed_at_key, #unsubscribe, #unsubscribe_to_email, #unsubscribe_to_optional_target

Class Method Details

.filtered_by_targetActiveRecord_AssociationRelation<Subscription>

Selects filtered subscriptions by target instance.

ActivityNotification::Subscription.filtered_by_target(@user)

is the same as

@user.subscriptions

Parameters:

  • target (Object)

    Target instance for filter

Returns:

  • (ActiveRecord_AssociationRelation<Subscription>)

    Database query of filtered subscriptions



43
# File 'lib/activity_notification/orm/active_record/subscription.rb', line 43

scope :filtered_by_target,  ->(target) { where(target: target) }

.uniq_keysArray<String>

Selects unique keys from query for subscriptions.

Returns:

  • (Array<String>)

    Array of subscription unique keys



51
52
53
54
55
# File 'lib/activity_notification/orm/active_record/subscription.rb', line 51

def self.uniq_keys
  # select method cannot be chained with order by other columns like created_at
  # select(:key).distinct.pluck(:key)
  pluck(:key).uniq
end

Instance Method Details

#targetObject

Belongs to target instance of this subscription as polymorphic association.

Returns:

  • (Object)

    Target instance of this subscription



14
# File 'lib/activity_notification/orm/active_record/subscription.rb', line 14

belongs_to :target,               polymorphic: true

#with_targetActiveRecord_AssociationRelation<Subscription>

Includes target instance with query for subscriptions.

Returns:

  • (ActiveRecord_AssociationRelation<Subscription>)

    Database query of subscriptions with target



47
# File 'lib/activity_notification/orm/active_record/subscription.rb', line 47

scope :with_target,               -> { includes(:target) }