Class: Aegis::Permissions
- Inherits:
-
Object
- Object
- Aegis::Permissions
- Defined in:
- lib/aegis/permissions.rb
Constant Summary collapse
- MISSING_ACTION_STRATEGIES =
[ :allow, :deny, :default_permission, :error ]
Class Method Summary collapse
- .action(*args, &block) ⇒ Object
- .alias_action(aliases) ⇒ Object
- .app_permissions(option) ⇒ Object
- .find_action_by_path(path, handle_missing = true) ⇒ Object
- .find_role_by_name(name) ⇒ Object
- .guess_action(resource_name, action_name, map = {}) ⇒ Object
- .inspect ⇒ Object
- .may!(user, path, *args) ⇒ Object
- .may?(user, path, *args) ⇒ Boolean
- .missing_action_means(strategy) ⇒ Object
- .missing_user_means(strategy_symbol = nil, &strategy_block) ⇒ Object
- .namespace(*args, &block) ⇒ Object
- .permission(*args) ⇒ Object
- .resource(*args, &block) ⇒ Object
- .resources(*args, &block) ⇒ Object
- .role(role_name, options = {}) ⇒ Object
- .roles ⇒ Object
Class Method Details
.action(*args, &block) ⇒ Object
31 32 33 34 |
# File 'lib/aegis/permissions.rb', line 31 def action(*args, &block) prepare @parser.action(*args, &block) end |
.alias_action(aliases) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/aegis/permissions.rb', line 20 def alias_action(aliases) prepare aliases.each do |key, value| @action_aliases[key.to_s] = value.to_s end end |
.app_permissions(option) ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/aegis/permissions.rb', line 92 def (option) if option.is_a?(Class) option else (option || '::Permissions').constantize end end |
.find_action_by_path(path, handle_missing = true) ⇒ Object
85 86 87 88 89 90 |
# File 'lib/aegis/permissions.rb', line 85 def find_action_by_path(path, handle_missing = true) compile action = @actions_by_path[path.to_s] action = handle_missing_action(action, path) if handle_missing action end |
.find_role_by_name(name) ⇒ Object
70 71 72 |
# File 'lib/aegis/permissions.rb', line 70 def find_role_by_name(name) @roles_by_name[name.to_s] end |
.guess_action(resource_name, action_name, map = {}) ⇒ Object
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/aegis/permissions.rb', line 74 def guess_action(resource_name, action_name, map = {}) compile action = nil action_name = action_name.to_s possible_paths = guess_action_paths(resource_name, action_name, map) possible_paths.detect do |path| action = find_action_by_path(path, false) end handle_missing_action(action, possible_paths.first) end |
.inspect ⇒ Object
100 101 102 103 |
# File 'lib/aegis/permissions.rb', line 100 def inspect compile "Permissions(#{@root_resource.inspect})" end |
.may!(user, path, *args) ⇒ Object
55 56 57 |
# File 'lib/aegis/permissions.rb', line 55 def may!(user, path, *args) query_action(:may!, user, path, *args) end |
.may?(user, path, *args) ⇒ Boolean
51 52 53 |
# File 'lib/aegis/permissions.rb', line 51 def may?(user, path, *args) query_action(:may?, user, path, *args) end |
.missing_action_means(strategy) ⇒ Object
9 10 11 12 13 |
# File 'lib/aegis/permissions.rb', line 9 def missing_action_means(strategy) prepare MISSING_ACTION_STRATEGIES.include?(strategy) or raise Aegis::InvalidSyntax, "missing_action_means must be one of #{MISSING_ACTION_STRATEGIES.inspect}" @missing_action_strategy = strategy end |
.missing_user_means(strategy_symbol = nil, &strategy_block) ⇒ Object
15 16 17 18 |
# File 'lib/aegis/permissions.rb', line 15 def missing_user_means(strategy_symbol = nil, &strategy_block) prepare @missing_user_strategy = strategy_symbol || strategy_block end |
.namespace(*args, &block) ⇒ Object
41 42 43 44 |
# File 'lib/aegis/permissions.rb', line 41 def namespace(*args, &block) prepare @parser.namespace(*args, &block) end |
.permission(*args) ⇒ Object
27 28 29 |
# File 'lib/aegis/permissions.rb', line 27 def (*args) raise Aegis::InvalidSyntax, "The Aegis API has changed. See http://wiki.github.com/makandra/aegis/upgrading-to-aegis-2 for migration instructions." end |
.resource(*args, &block) ⇒ Object
36 37 38 39 |
# File 'lib/aegis/permissions.rb', line 36 def resource(*args, &block) prepare @parser.resource(*args, &block) end |
.resources(*args, &block) ⇒ Object
46 47 48 49 |
# File 'lib/aegis/permissions.rb', line 46 def resources(*args, &block) prepare @parser.resources(*args, &block) end |
.role(role_name, options = {}) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/aegis/permissions.rb', line 59 def role(role_name, = {}) role_name = role_name.to_s role_name != 'everyone' or raise Aegis::InvalidSyntax, "Cannot define a role named: #{role_name}" @roles_by_name ||= {} @roles_by_name[role_name] = Aegis::Role.new(role_name, ) end |
.roles ⇒ Object
66 67 68 |
# File 'lib/aegis/permissions.rb', line 66 def roles @roles_by_name.values.sort end |