Class: ActivityNotification::ORM::Mongoid::Subscription

Inherits:
Object
  • Object
show all
Includes:
Association, SubscriptionApi, Mongoid::Attributes::Dynamic, Mongoid::Document, Mongoid::Timestamps
Defined in:
lib/activity_notification/orm/mongoid/subscription.rb

Overview

Subscription model implementation generated by ActivityNotification.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SubscriptionApi

#as_json, #optional_target_names, #subscribe, #subscribe_to_email, #subscribe_to_optional_target, #subscribing_to_optional_target?, #unsubscribe, #unsubscribe_to_email, #unsubscribe_to_optional_target

Methods included from Association

#update

Methods included from Mongoid::Document

#as_json

Class Method Details

.filtered_by_targetMongoid::Criteria<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:

  • (Mongoid::Criteria<Subscription>)

    Database query of filtered subscriptions



53
# File 'lib/activity_notification/orm/mongoid/subscription.rb', line 53

scope :filtered_by_target,  ->(target) { filtered_by_association("target", target) }

.uniq_keysArray<String>

Selects unique keys from query for subscriptions.

Returns:

  • (Array<String>)

    Array of subscription unique keys



64
65
66
67
68
# File 'lib/activity_notification/orm/mongoid/subscription.rb', line 64

def self.uniq_keys
  # distinct method cannot keep original sort
  # distinct(: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



19
# File 'lib/activity_notification/orm/mongoid/subscription.rb', line 19

belongs_to_polymorphic_xdb_record :target

#whereMongoid::Criteria<Subscription>

Selects filtered subscriptions by type of the object. Filtering with ActivityNotification::Subscription is defined as default scope.

Returns:

  • (Mongoid::Criteria<Subscription>)

    Database query of filtered subscriptions



44
# File 'lib/activity_notification/orm/mongoid/subscription.rb', line 44

default_scope -> { where(_type: "ActivityNotification::Subscription") }

#with_targetMongoid::Criteria<Subscription>

Includes target instance with query for subscriptions.

Returns:

  • (Mongoid::Criteria<Subscription>)

    Database query of subscriptions with target



57
# File 'lib/activity_notification/orm/mongoid/subscription.rb', line 57

scope :with_target,               -> { }