Module: SocialStream::Models::Object::InstanceMethods

Defined in:
lib/social_stream/models/object.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

Delegate missing methods to ActivityObject, if they exist there



36
37
38
39
40
41
42
43
44
# File 'lib/social_stream/models/object.rb', line 36

def method_missing(method, *args, &block)
  super
rescue NameError => object_error 
  # These methods must be raised to avoid loops (the :activity_object association calls here again)
  exceptions = [ :_activity_object_id ]
  raise object_error if exceptions.include?(method)

  activity_object!.__send__ method, *args, &block
end

Instance Method Details

#_activity_parentObject



104
105
106
# File 'lib/social_stream/models/object.rb', line 104

def _activity_parent
  @_activity_parent ||= Activity.find(_activity_parent_id)
end

#_contactObject



78
79
80
# File 'lib/social_stream/models/object.rb', line 78

def _contact
  @_contact ||= author && owner && author.contact_to!(owner)
end

#_contact_idObject



82
83
84
# File 'lib/social_stream/models/object.rb', line 82

def _contact_id
  _contact.try(:id)
end

#_relation_idsObject



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/social_stream/models/object.rb', line 86

def _relation_ids
  @_relation_ids ||=
    if _contact_id.nil?
      nil
    else
      # FIXME: repeated in Activity#fill_relations
      if _contact.reflexive?
        _contact.sender.relation_customs.map(&:id)
      else
         _contact.
           receiver.
           relation_customs.
           allow(_contact.sender, 'create', 'activity').
           map(&:id)
      end
    end
end

#activitiesObject

All the activities with this object



57
58
59
60
61
# File 'lib/social_stream/models/object.rb', line 57

def activities
  Activity.
    includes(:activity_objects => self.class.to_s.underscore).
    where("#{ self.class.quoted_table_name }.id" => self.id)
end

#activity_object!Object



31
32
33
# File 'lib/social_stream/models/object.rb', line 31

def activity_object!
  activity_object || build_activity_object(:object_type => self.class.to_s)
end

#build_post_activityObject

Build the post activity when this object is not saved



64
65
66
67
# File 'lib/social_stream/models/object.rb', line 64

def build_post_activity
  Activity.new :contact_id   => _contact_id,
               :relation_ids => Array(_relation_ids)
end

#create_activity_object_with_typeObject

Build corresponding ActivityObject including this class type



72
73
74
75
76
# File 'lib/social_stream/models/object.rb', line 72

def create_activity_object_with_type #:nodoc:
  o = create_activity_object! :object_type => self.class.to_s
	  # WEIRD: Rails 3.1.0.rc3 does not assign activity_object_id
	  self.activity_object_id = o.id
end

#represented_author?Boolean

Was the author represented with this object was created?

Returns:

  • (Boolean)


52
53
54
# File 'lib/social_stream/models/object.rb', line 52

def represented_author?
  author_id == user_author_id
end

#respond_to?(*args) ⇒ Boolean

ActivityObject handles some methods

Returns:

  • (Boolean)


47
48
49
# File 'lib/social_stream/models/object.rb', line 47

def respond_to? *args
  super || activity_object!.respond_to?(*args)
end