Sha256: 920a3fee3d45146e5f0585e5f759d87593bad421c716f22b51b43800328c72f2
Contents?: true
Size: 1.02 KB
Versions: 1
Compression:
Stored size: 1.02 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.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 scope = {: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.7.alpha | lib/permissive/permission.rb |