Sha256: 6f62afe80648ac83a9d20f3b0feb144d698d4aea968edafae1985239a0c677be
Contents?: true
Size: 1011 Bytes
Versions: 2
Compression:
Stored size: 1011 Bytes
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}"}.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 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
permissive-0.2.5.alpha | lib/permissive/permission.rb |
permissive-0.2.4.alpha | lib/permissive/permission.rb |