Skip to content
Browse files

support for specifing multiple controllers in single execution of 'al…

…low' method
  • Loading branch information...
1 parent 15cc9d6 commit 0338f75be65e08849d139f331c5f357fd17c00c3 @grzegorzkazulak grzegorzkazulak committed Oct 23, 2010
Showing with 18 additions and 2 deletions.
  1. +16 −2 lib/polar/permissions.rb
  2. +2 −0 spec/spec_helper.rb
View
18 lib/polar/permissions.rb
@@ -82,11 +82,11 @@ def initialize(method)
end
def allow(*params)
- add(:allow, params)
+ dispatch(:allow, params)
end
def deny(*params)
- add(:deny, params)
+ dispatch(:deny, params)
end
def add(perm_type, params)
@@ -97,5 +97,19 @@ def add(perm_type, params)
Polar::Permissions.defined_store[self[:permission_name]] ||= []
Polar::Permissions.defined_store[self[:permission_name]] << self
end
+
+ private
+
+ def dispatch(access_type, params)
+ perm_objects = params.first
+ if perm_objects.is_a?(Array)
+ perm_objects.each do |po|
+ params[0] = po
+ add(access_type, params)
+ end
+ else
+ add(access_type, params)
+ end
+ end
end
end
View
2 spec/spec_helper.rb
@@ -53,6 +53,8 @@
Polar.define :permissions do |gp|
gp.edit_profile do |c|
c.allow :users_controller, :only => [:edit, :update]
+ c.allow [:groups_controller, :clients_controller]
+ c.allow [:articles_controller, :contacts_controller], :only => [:index]
end
gp.add_addresses do |c|

0 comments on commit 0338f75

Please sign in to comment.
Something went wrong with that request. Please try again.