Class: ActivityObject
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ActivityObject
- Defined in:
- app/models/activity_object.rb
Overview
The ActivityObject is any object that receives actions. Examples are creating post, liking a comment, contacting a user.
ActivityObject subtypes
All post, comment and user are objects. Social Stream privides 3 ActivityObject subtypes, Post, Comment and Actor. The application developer can define as many ActivityObject subtypes as required. Objects are added to config/initializers/social_stream.rb
Instance Attribute Summary collapse
-
#_activity_parent_id ⇒ Object
Returns the value of attribute _activity_parent_id.
Instance Method Summary collapse
- #_activity_parent ⇒ Object
-
#action_from(actor) ⇒ Object
Return the Action model to an Actor.
- #actor! ⇒ Object
-
#acts_as_actor? ⇒ Boolean
Does this ActivityObject has Actor?.
-
#authored_or_owned_by?(subject) ⇒ Boolean
subject was the author, user author or owner of this ActivityObject?.
-
#build_post_activity ⇒ Object
Build the post activity when this object is not saved.
-
#object ⇒ Object
The object of this activity object.
-
#post_activity ⇒ Object
The activity in which this activity_object was created.
-
#received_action_by(actor_id) ⇒ Object
Obtain the ActivityAction between this ActivityObject and the Actor identified by actor_id.
-
#received_action_by!(actor_id) ⇒ Object
Obtain received_action_by(actor_id) or create it if it does not exist.
-
#received_role_action(role) ⇒ Object
Get the first ActivityAction that has activated the role flag.
-
#represented_author? ⇒ Boolean
Was the author represented when this ActivityObject was created?.
Instance Attribute Details
#_activity_parent_id ⇒ Object
Returns the value of attribute _activity_parent_id.
12 13 14 |
# File 'app/models/activity_object.rb', line 12 def _activity_parent_id @_activity_parent_id end |
Instance Method Details
#_activity_parent ⇒ Object
197 198 199 |
# File 'app/models/activity_object.rb', line 197 def _activity_parent @_activity_parent ||= Activity.find(_activity_parent_id) end |
#action_from(actor) ⇒ Object
Return the Action model to an Actor
180 181 182 |
# File 'app/models/activity_object.rb', line 180 def action_from(actor) received_actions.sent_by(actor).first end |
#actor! ⇒ Object
175 176 177 |
# File 'app/models/activity_object.rb', line 175 def actor! actor || raise("Unknown Actor for ActivityObject: #{ inspect }") end |
#acts_as_actor? ⇒ Boolean
Does this ActivityObject has Actor?
171 172 173 |
# File 'app/models/activity_object.rb', line 171 def acts_as_actor? object_type == "Actor" end |
#authored_or_owned_by?(subject) ⇒ Boolean
subject was the author, user author or owner of this ActivityObject?
150 151 152 153 154 155 156 |
# File 'app/models/activity_object.rb', line 150 def (subject) return false if subject.blank? received_actions. merge(ActivityAction.(subject)). any? end |
#build_post_activity ⇒ Object
Build the post activity when this object is not saved
190 191 192 193 194 195 |
# File 'app/models/activity_object.rb', line 190 def build_post_activity Activity.new :author => , :user_author => , :owner => owner, :relation_ids => relation_ids end |
#object ⇒ Object
The object of this activity object
164 165 166 167 168 |
# File 'app/models/activity_object.rb', line 164 def object subtype_instance.is_a?(Actor) ? subtype_instance.subject : subtype_instance end |
#post_activity ⇒ Object
The activity in which this activity_object was created
185 186 187 |
# File 'app/models/activity_object.rb', line 185 def post_activity activities.includes(:activity_verb).where('activity_verbs.name' => 'post').first end |
#received_action_by(actor_id) ⇒ Object
Obtain the ActivityAction between this ActivityObject and the Actor identified by actor_id
97 98 99 100 |
# File 'app/models/activity_object.rb', line 97 def received_action_by(actor_id) received_actions. find{ |a| a.actor_id == actor_id } end |
#received_action_by!(actor_id) ⇒ Object
Obtain received_action_by(actor_id) or create it if it does not exist
104 105 106 107 |
# File 'app/models/activity_object.rb', line 104 def received_action_by!(actor_id) received_action_by(actor_id) || received_actions.build(:actor_id => actor_id) end |
#received_role_action(role) ⇒ Object
Get the first ActivityAction that has activated the role flag
110 111 112 113 |
# File 'app/models/activity_object.rb', line 110 def received_role_action(role) received_actions. find{ |a| a.__send__ "#{ role }?" } end |
#represented_author? ⇒ Boolean
Was the author represented when this ActivityObject was created?
159 160 161 |
# File 'app/models/activity_object.rb', line 159 def != end |