Module: Streama::Activity

Extended by:
ActiveSupport::Concern
Defined in:
lib/streama/activity.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#load_instance(type) ⇒ Mongoid::Document

Returns an instance of an actor, object or target

Parameters:

  • type (Symbol)

    The data type (actor, object, target) to return an instance for.

Returns:

  • (Mongoid::Document)

    document A mongoid document instance


88
89
90
# File 'lib/streama/activity.rb', line 88

def load_instance(type)
  (data = self.read_attribute(type)).is_a?(Hash) ? data['type'].to_s.camelcase.constantize.find(data['id']) : data
end

#publish(options = {}) ⇒ Object

Publishes the activity to the receivers

Parameters:

  • options (Hash) (defaults to: {})

    The options to publish with.


76
77
78
79
80
81
# File 'lib/streama/activity.rb', line 76

def publish(options = {})
  actor = load_instance(:actor)
  self.receivers = (options[:receivers] || actor.followers).map { |r| { :id => r.id, :type => r.class.to_s } }
  self.save
  self
end

#refresh_dataObject


92
93
94
95
# File 'lib/streama/activity.rb', line 92

def refresh_data
  assign_data
  save(:validates_presence_of => false)
end