Module: MongoMapper::Plugins::CustomScope::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

#count(options = {}) ⇒ Object



19
20
21
# File 'lib/mongo_mapper_ext/plugins/custom_scope.rb', line 19

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

#find_many(options = {}) ⇒ Object



15
16
17
# File 'lib/mongo_mapper_ext/plugins/custom_scope.rb', line 15

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

#find_one(options = {}) ⇒ Object



11
12
13
# File 'lib/mongo_mapper_ext/plugins/custom_scope.rb', line 11

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

#query(options = {}) ⇒ Object



7
8
9
# File 'lib/mongo_mapper_ext/plugins/custom_scope.rb', line 7

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

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



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/mongo_mapper_ext/plugins/custom_scope.rb', line 23

def with_exclusive_scope options = {}, &block
  Thread.current['mm_with_exclusive_scope'].must_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



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/mongo_mapper_ext/plugins/custom_scope.rb', line 35

def with_scope options = {}, &block
  Thread.current['mm_with_exclusive_scope'].must_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