Sha256: e88fcea81526b25aa76cee14801af94b6f26c398937a63e5d2e02119eb82514d
Contents?: true
Size: 1.01 KB
Versions: 1
Compression:
Stored size: 1.01 KB
Contents
# This is the core permission class that Permissive uses. module Permissive class Permission < ActiveRecord::Base belongs_to :permitted_object, :polymorphic => true belongs_to :scoped_object, :polymorphic => true named_scope :granted, lambda {|*permissions| {:conditions => permissions.flatten.map{|bit| "(mask & #{bit}) > 0"}.join(' AND ')} } named_scope :on, lambda {|scoped_object| case scoped_object when ActiveRecord::Base {:conditions => {:scoped_object_id => scoped_object.id, :scoped_object_type => scoped_object.class.to_s}} when Class {:conditions => {:scoped_object_id => nil, :scoped_object_type => scoped_object.name}} when String, Symbol {:conditions => {:scoped_object_id => nil, :scoped_object_type => scoped_object.to_s.classify}} else {:conditions => {:scoped_object_id => nil, :scoped_object_type => nil}} end } set_table_name :permissive_permissions validates_presence_of :mask, :permitted_object end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
permissive-0.2.8.alpha | lib/permissive/permission.rb |