Module: Aegis::Permissions::ClassMethods
- Defined in:
- lib/aegis/permissions.rb
Instance Method Summary collapse
- #default_role(role_name, options = {}) ⇒ Object
- #denied?(*args) ⇒ Boolean
- #evaluate_permission_blocks(role, blocks, *args) ⇒ Object
- #find_all_role_names ⇒ Object
- #find_all_roles ⇒ Object
- #find_role_by_name(name) ⇒ Object
- #find_role_by_name!(name) ⇒ Object
- #may?(role_or_role_name, permission, *args) ⇒ Boolean
- #permission(*permission_name_or_names, &block) ⇒ Object
- #role(role_name, options = {}) ⇒ Object
Instance Method Details
#default_role(role_name, options = {}) ⇒ Object
15 16 17 |
# File 'lib/aegis/permissions.rb', line 15 def default_role(role_name, = {}) @default_role = role(role_name, ) end |
#denied?(*args) ⇒ Boolean
61 62 63 |
# File 'lib/aegis/permissions.rb', line 61 def denied?(*args) !allowed?(*args) end |
#evaluate_permission_blocks(role, blocks, *args) ⇒ Object
56 57 58 59 |
# File 'lib/aegis/permissions.rb', line 56 def (role, blocks, *args) evaluator = Aegis::PermissionEvaluator.new(role) evaluator.evaluate(blocks, args) end |
#find_all_role_names ⇒ Object
25 26 27 |
# File 'lib/aegis/permissions.rb', line 25 def find_all_role_names @roles_by_name.keys end |
#find_all_roles ⇒ Object
29 30 31 |
# File 'lib/aegis/permissions.rb', line 29 def find_all_roles @roles_by_name.values.sort end |
#find_role_by_name(name) ⇒ Object
33 34 35 36 37 |
# File 'lib/aegis/permissions.rb', line 33 def find_role_by_name(name) return nil if name == "" # If name is nil, try to return the default role. name.nil? ? @default_role : @roles_by_name[name.to_sym] end |
#find_role_by_name!(name) ⇒ Object
39 40 41 |
# File 'lib/aegis/permissions.rb', line 39 def find_role_by_name!(name) find_role_by_name(name) or raise "Undefined role: #{name}" end |
#may?(role_or_role_name, permission, *args) ⇒ Boolean
50 51 52 53 54 |
# File 'lib/aegis/permissions.rb', line 50 def may?(role_or_role_name, , *args) role = role_or_role_name.is_a?(Aegis::Role) ? role_or_role_name : find_role_by_name(role_or_role_name) blocks = @permission_blocks[.to_sym] (role, blocks, *args) end |
#permission(*permission_name_or_names, &block) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/aegis/permissions.rb', line 43 def (*, &block) = Array().map(&:to_s) .each do || (, &block) end end |
#role(role_name, options = {}) ⇒ Object
19 20 21 22 23 |
# File 'lib/aegis/permissions.rb', line 19 def role(role_name, = {}) role_name = role_name.to_sym role_name != Aegis::Constants::EVERYONE_ROLE_NAME or raise "Cannot define a role named: #{Aegis::Constants::EVERYONE_ROLE_NAME}" @roles_by_name[role_name] = Aegis::Role.new(role_name, self, ) end |