Created
November 21, 2013 12:56
-
-
Save ys/7581114 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Follow < ActiveRecord::Base | |
belongs_to :follower, class_name: 'User' | |
belongs_to :followee, class_name: 'User' | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Post < ActiveRecord::Base | |
belongs_to :user | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PostPolicy = Struct.new(:user, :post) do | |
self::Scope = Struct.new(:user, :scope) do | |
def resolve | |
scope.joins(:user) | |
.where(users[:private_profile].eq(false) | |
.or(posts[:user_id].eq(user.id)) | |
.or(posts[:user_id].in(followers))) | |
end | |
end | |
def followers | |
follows.where(follows[:follower_id].eq(user.id)) | |
.where(follows[:approved].eq(true)).project(:followee_id) | |
end | |
def follows | |
Arel::Table.new(:follows) | |
end | |
def users | |
Arel::Table.new(:users) | |
end | |
def posts | |
Arel::Table.new(:posts) | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
#has a private_profile flag | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment