Sha256: c6010aa1b2c01b75f72220b55a3452fe4106770e3025bf208618d30dcb577c3f

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.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 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.6.alpha lib/permissive/permission.rb