Add instance methods here
Remove shareble object
# File lib/acts_as_shareable/shareable.rb, line 79 def remove_share_from(object, by_user) shareable = self to = object.class.base_class s = Share.where("shareable_type = ? and shareable_id = ? and shared_to_type = ? and shared_to_id = ? and user_id=?", shareable, id, to, object.id, by_user.id) if s s.destroy reload end end
Create new shareble
# File lib/acts_as_shareable/shareable.rb, line 70 def share_to(object, by_user) unless shared_to?(object, by_user) s = Share.new(user_id: by_user.id, shared_to_type: object.class.to_s, shared_to_id: object.id) self.shares << s self.save! end end
Find shareble with specific info
# File lib/acts_as_shareable/shareable.rb, line 90 def shared_to?(object, by_user) shareable = self to = object.class.base_class s = Share.where("shareable_type = ? and shareable_id = ? and shared_to_type = ? and shared_to_id = ? and user_id=?", shareable, id, to, object.id, by_user.id) return !s.nil? end
Users to whom the object is shared
# File lib/acts_as_shareable/shareable.rb, line 98 def shared_with_users shared_with_individual_users.union(shared_with_group_users).uniq end