class Share

Schema Information

Table name: shares

id             :integer          not null, primary key
user_id        :integer
shareable_type :string(30)
shareable_id   :integer
shared_to_type :string(30)
shared_to_id   :integer
university_id     :integer
created_at     :datetime
updated_at     :datetime

Public Class Methods

find_by_shareable_and_shared_to(shareable, object) click to toggle source

To find shares by shareable and shared to object

# File app/models/share.rb, line 33
def self.find_by_shareable_and_shared_to(shareable, object)
  where(shareable: shareable, shared_to: object)
end
find_by_shared_to(object) click to toggle source

To find sahres by shared to objects

# File app/models/share.rb, line 28
def self.find_by_shared_to(object)
  where(shared_to: object)
end
find_shares_by_user(user) click to toggle source

To find shares by user

# File app/models/share.rb, line 23
def self.find_shares_by_user(user)
  where(user: user).order("created_at DESC")
end

Public Instance Methods

shared_to_group?() click to toggle source

Returns true if shared to type is Group

# File app/models/share.rb, line 43
def shared_to_group?
  shared_to_type == 'Group'
end
shared_to_user?() click to toggle source

Returns true if shared_to_type is user

# File app/models/share.rb, line 38
def shared_to_user?
  shared_to_type == 'User'
end