lib/trust/permissions.rb
def _role(existing_permissions, *roles, &block)
        if block_given?
          if @@can_expressions > 0
            @@can_expressions = 0
            raise RoleAssigmnentMissing 
          end
          @perms = {:can => [], :cannot => []}
          @in_role_block = true
          yield
          @in_role_block = false
          perms = @perms
        else
          if @@can_expressions > 1
            @@can_expressions = 0
            raise RoleAssigmnentMissing 
          end
          perms = roles.extract_options!
          unless perms.size >= 1 && (perms[:can] || perms[:cannot])
            raise ArgumentError, "Must have a block or a can or a cannot expression: #{perms.inspect}"
          end
          @@can_expressions = 0
        end
        roles.flatten.each do |role|
          existing_permissions[role] ||= []
          if perms[:cannot] && perms[:cannot].size > 0
            perms[:cannot].each do |p|
              existing_permissions[role].delete_if { |perm| perm[0] == p  }
            end
          end
          if perms[:can] && perms[:can].size > 0
            existing_permissions[role] += perms[:can]
          end
        end
        existing_permissions
      end
# Assign default requirement for whitelisting paremeters
#
# See {ActionController::Parameters.require} for how this works in Rails
# 
Assign default requirement for whitelisting paremeters
See {ActionController::Parameters.require} for how this works in Rails
Assign default requirement for whitelisting paremeters See { ActionController :: Parameters . require } for how this works in Rails
def _role(existing_permissions, *roles, &block)
        if block_given?
          if @@can_expressions > 0
            @@can_expressions = 0
            raise RoleAssigmnentMissing 
          end
          @perms = {:can => [], :cannot => []}
          @in_role_block = true
          yield
          @in_role_block = false
          perms = @perms
        else
          if @@can_expressions > 1
            @@can_expressions = 0
            raise RoleAssigmnentMissing 
          end
          perms = roles.extract_options!
          unless perms.size >= 1 && (perms[:can] || perms[:cannot])
            raise ArgumentError, "Must have a block or a can or a cannot expression: #{perms.inspect}"
          end
          @@can_expressions = 0
        end
        roles.flatten.each do |role|
          existing_permissions[role] ||= []
          if perms[:cannot] && perms[:cannot].size > 0
            perms[:cannot].each do |p|
              existing_permissions[role].delete_if { |perm| perm[0] == p  }
            end
          end
          if perms[:can] && perms[:can].size > 0
            existing_permissions[role] += perms[:can]
          end
        end
        existing_permissions
      end
def _role ( existing_permissions , * roles , & block ) if block_given? if @@can_expressions > 0 @@can_expressions = 0 raise RoleAssigmnentMissing end @perms = { :can => [ ] , :cannot => [ ] } @in_role_block = true yield @in_role_block = false perms = @perms else if @@can_expressions > 1 @@can_expressions = 0 raise RoleAssigmnentMissing end perms = roles . extract_options! unless perms . size >= 1 && ( perms [ :can ] || perms [ :cannot ] ) raise ArgumentError , "Must have a block or a can or a cannot expression: #{perms.inspect}" end @@can_expressions = 0 end roles . flatten . each do | role | existing_permissions [ role ] ||= [ ] if perms [ :cannot ] && perms [ :cannot ] . size > 0 perms [ :cannot ] . each do | p | existing_permissions [ role ] . delete_if { | perm | perm [ 0 ] == p } end end if perms [ :can ] && perms [ :can ] . size > 0 existing_permissions [ role ] += perms [ :can ] end end existing_permissions end
Assign default requirement for whitelisting paremeters
See {ActionController::Parameters.require} for how this works in Rails
Assign default requirement for whitelisting paremeters See { ActionController :: Parameters . require } for how this works in Rails
existing_permissions
roles
block