module ActsAsShareable::Shareable::InstanceMethods

Add instance methods here

Public Instance Methods

remove_share_from(object, by_user) click to toggle source

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
share_to(object, by_user) click to toggle source

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
shared_to?(object, by_user) click to toggle source

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
shared_with_users() click to toggle source

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