Class: Bustle::Activities

Inherits:
Object
  • Object
show all
Includes:
Concern::ByPublisher, Concern::Filterable
Defined in:
lib/bustle/activities.rb

Constant Summary collapse

RESOURCE_NAME =
'Bustle::Activity'

Class Method Summary collapse

Class Method Details

.add(publisher, data = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/bustle/activities.rb', line 9

def add(publisher, data = {})
  data = data.dup

  if resource = data.delete(:resource)
    data[:resource_class] = resource.class.name
    data[:resource_id]    = resource.id
  end

  Activity.to_adapter.create!(
    :resource_class => data[:resource_class],
    :resource_id    => data[:resource_id],
    :action         => data[:action],
    :data           => data[:data],
    :publisher_id   => publisher.id
  )
end

.for(subscriber, conditions = {}) ⇒ Object



26
27
28
29
30
# File 'lib/bustle/activities.rb', line 26

def for(subscriber, conditions = {})
  publisher_ids = Subscriptions.for(subscriber).map(&:publisher_id)

  filter({ :publisher_id => publisher_ids }.merge(conditions))
end