Last active
August 17, 2016 17:37
-
-
Save mjc-gh/59540469e90502c1592fa6764bd54cc8 to your computer and use it in GitHub Desktop.
Simon Says Roleable
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 Admin < ActiveRecord::Base | |
include SimonSays::Roleable | |
has_roles :design, :support, :moderator, as: :access | |
end | |
# > Admin.new.access | |
# => [] | |
# > Admin.new(access: :support).access | |
# => [:support] |
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 Membership < ActiveRecord::Base | |
include SimonSays::Roleable | |
belongs_to :user | |
belongs_to :document | |
has_roles :download, :edit, :delete, | |
end | |
# > Membership.new(roles: Membership::ROLES).roles | |
# => [:download, :edit, :delete] |
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 | |
include SimonSays::Roleable | |
has_roles :add, :edit, :delete | |
end | |
# > User.new.roles | |
# => [] | |
# > u = User.new(roles: %i[add edit]) | |
# | |
# > u.roles | |
# => [:add, :edit] | |
# > u.has_add? | |
# => true | |
# > u.has_delete? | |
# => false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment