-
Notifications
You must be signed in to change notification settings - Fork 403
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactored scopes code for Role class
added a parameter to ask for roles binded to specific resource closes #67
- Loading branch information
Showing
8 changed files
with
70 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module Rolify | ||
module Adapter | ||
module Scopes | ||
def global | ||
where(:resource_type => nil, :resource_id => nil) | ||
end | ||
|
||
def class_scoped(resource_type = nil) | ||
where_conditions = "resource_type IS NOT NULL AND resource_id IS NULL" | ||
where_conditions = [ "resource_type = ? AND resource_id IS NULL", resource_type.name ] if resource_type | ||
where(where_conditions) | ||
end | ||
|
||
def instance_scoped(resource_type = nil) | ||
where_conditions = "resource_type IS NOT NULL AND resource_id IS NOT NULL" | ||
if resource_type | ||
if resource_type.is_a? Class | ||
where_conditions = [ "resource_type = ? AND resource_id IS NOT NULL", resource_type.name ] | ||
else | ||
where_conditions = [ "resource_type = ? AND resource_id = ?", resource_type.class.name, resource_type.id ] | ||
end | ||
end | ||
where(where_conditions) | ||
end | ||
end | ||
end | ||
end |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module Rolify | ||
module Adapter | ||
module Scopes | ||
def global | ||
where(:resource_type => nil, :resource_id => nil) | ||
end | ||
|
||
def class_scoped(resource_type = nil) | ||
where_conditions = { :resource_type.ne => nil, :resource_id => nil } | ||
where_conditions = { :resource_type => resource_type.name, :resource_id => nil } if resource_type | ||
where(where_conditions) | ||
end | ||
|
||
def instance_scoped(resource_type = nil) | ||
where_conditions = { :resource_type.ne => nil, :resource_id.ne => nil } | ||
if resource_type | ||
if resource_type.is_a? Class | ||
where_conditions = { :resource_type => resource_type.name, :resource_id.ne => nil } | ||
else | ||
where_conditions = { :resource_type => resource_type.class.name, :resource_id => resource_type.id } | ||
end | ||
end | ||
where(where_conditions) | ||
end | ||
end | ||
end | ||
end |
This file contains 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
This file contains 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
This file contains 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