Module: MongoMapper::Plugins::DefaultScope::ClassMethods

Defined in:
lib/mongo_mapper_ext/plugins/default_scope.rb

Instance Method Summary collapse

Instance Method Details

#count(options = {}) ⇒ Object



14
15
16
# File 'lib/mongo_mapper_ext/plugins/default_scope.rb', line 14

def count options={}
  super default_scope_options.merge(options)
end

#find_many(options = {}) ⇒ Object



10
11
12
# File 'lib/mongo_mapper_ext/plugins/default_scope.rb', line 10

def find_many options = {}
  super default_scope_options.merge(options)
end

#find_one(options = {}) ⇒ Object



6
7
8
# File 'lib/mongo_mapper_ext/plugins/default_scope.rb', line 6

def find_one options = {}
  super default_scope_options.merge(options)
end

#with_exclusive_scope(options = {}, &block) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/mongo_mapper_ext/plugins/default_scope.rb', line 18

def with_exclusive_scope options = {}, &block
  Thread.current['mm_with_exclusive_scope'].should! :be_nil
  
  before = Thread.current['mm_with_exclusive_scope']
  begin
    Thread.current['mm_with_exclusive_scope'] = options
    block.call if block
  ensure
    Thread.current['mm_with_exclusive_scope'] = before
  end
end

#with_scope(options = {}, &block) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/mongo_mapper_ext/plugins/default_scope.rb', line 30

def with_scope options = {}, &block
  Thread.current['mm_with_exclusive_scope'].should! :be_nil
  
  before = Thread.current['mm_with_scope']
  begin
    options = before.merge options if before
    Thread.current['mm_with_scope'] = options
    block.call if block
  ensure
    Thread.current['mm_with_scope'] = before
  end
end