Permalink
Browse files

addressing Issue #1: tackling development mode injections

  • Loading branch information...
1 parent d2161e2 commit 40a66f6a135908390f8cc8e13761dedfac8db607 @matthewvermaak committed Oct 9, 2009
Showing with 26 additions and 7 deletions.
  1. +13 −5 app/models/sanction/role/definition.rb
  2. +11 −0 init.rb
  3. +2 −2 lib/sanction.rb
@@ -51,11 +51,11 @@ def wildcard?
end
def self.for(principal)
- roles_by_principal[principal] || []
+ roles_by_principal[principal.to_s] || []
end
def self.over(permissionable)
- roles_by_permissionable[permissionable] || []
+ roles_by_permissionable[permissionable.to_s] || []
end
def self.with(name)
@@ -200,8 +200,12 @@ def attribute_principals(arr)
if(arr == :all)
self.principals = Sanction.principals
end
-
- self.principals = [self.principals] unless self.principals.is_a? Array
+
+ if self.principals.is_a? Array
+ self.principals.map!(&:name)
+ else
+ self.principals = [self.principals.name]
+ end
end
def attribute_permissionables(arr)
@@ -213,7 +217,11 @@ def attribute_permissionables(arr)
self.permissionables = []
end
- self.permissionables = [self.permissionables] unless self.permissionables.is_a? Array
+ if self.permissionables.is_a? Array
+ self.permissionables.map!(&:name)
+ else
+ self.permissionables = [self.permissionables.name]
+ end
end
def establish_permissions(permission_options)
View
@@ -1,2 +1,13 @@
# Include hook code here
require 'sanction'
+
+##
+# ENSURE Sanction injections are performed
+#
+unless Rails.configuration.cache_classes
+ require 'dispatcher' unless defined?(::Dispatcher)
+
+ Dispatcher.to_prepare do
+ Sanction.do_injections!
+ end
+end
View
@@ -69,13 +69,13 @@ def self.do_injections!
def self.inject_principals!
self.principals.each do |principal|
- principal.send(:include, Sanction::Principal)
+ principal.name.to_s.constantize.send(:include, Sanction::Principal)
end
end
def self.inject_permissionables!
self.permissionables.each do |permissionable|
- permissionable.send(:include, Sanction::Permissionable)
+ permissionable.name.to_s.constantize.send(:include, Sanction::Permissionable)
end
end
end

0 comments on commit 40a66f6

Please sign in to comment.