lib/role_on.rb in darkhelmet-role_on-0.2.1 vs lib/role_on.rb in darkhelmet-role_on-0.2.2
- old
+ new
@@ -31,18 +31,11 @@
alias :has_roles? :has_role?
end
module RoleOnUserClassMethods
def helper_for(role,name = role.to_s.pluralize)
- (class << self; self; end).class_eval do
- define_method("all_#{name}") do
- User.find(:all, :conditions => ['role_id = ?', Role[role].id], :joins => :roles)
- end
-
- define_method("all_non_#{name}") do
- User.find(:all, :conditions => [ 'roles.id is ? or roles.id != ?', nil, Role[role].id ], :include => :roles)
- end
- end
+ named_scope(name, :conditions => ['role_id = ?', Role[role].id], :joins => :roles)
+ named_scope("non_#{name}", :conditions => [ 'roles.id is ? or roles.id != ?', nil, Role[role].id ], :joins => :roles)
end
end
def self.included(klass)
if User == klass