Module: Rolify::Adapter::Scopes

Defined in:
lib/rolify/adapters/mongoid/scopes.rb,
lib/rolify/adapters/active_record/scopes.rb

Instance Method Summary collapse

Instance Method Details

#class_scoped(resource_type = nil) ⇒ Object



8
9
10
11
12
# File 'lib/rolify/adapters/mongoid/scopes.rb', line 8

def class_scoped(resource_type = nil)
  where_conditions = { :resource_type.ne => nil, :resource_id => nil }
  where_conditions = { :resource_type => resource_type.name, :resource_id => nil } if resource_type
  where(where_conditions)
end

#globalObject



4
5
6
# File 'lib/rolify/adapters/mongoid/scopes.rb', line 4

def global
  where(:resource_type => nil, :resource_id => nil)
end

#instance_scoped(resource_type = nil) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rolify/adapters/mongoid/scopes.rb', line 14

def instance_scoped(resource_type = nil)
  where_conditions = { :resource_type.ne => nil, :resource_id.ne => nil }
  if resource_type
    if resource_type.is_a? Class
      where_conditions = { :resource_type => resource_type.name, :resource_id.ne => nil }
    else
      where_conditions = { :resource_type => resource_type.class.name, :resource_id => resource_type.id }
    end
  end
  where(where_conditions)
end