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

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

Instance Method Summary collapse

Instance Method Details

#count(options = {}) ⇒ Object



17
18
19
# File 'lib/mongo_mapper_ext/mongo_mapper/plugins/custom_scope.rb', line 17

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

#find_many(options = {}) ⇒ Object



13
14
15
# File 'lib/mongo_mapper_ext/mongo_mapper/plugins/custom_scope.rb', line 13

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

#find_one(options = {}) ⇒ Object



9
10
11
# File 'lib/mongo_mapper_ext/mongo_mapper/plugins/custom_scope.rb', line 9

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

#query(options = {}) ⇒ Object



5
6
7
# File 'lib/mongo_mapper_ext/mongo_mapper/plugins/custom_scope.rb', line 5

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

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



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

def with_exclusive_scope options = {}, &block
  raise "exclusive scope already applied, can't apply it twice!" if Thread.current['mm_with_exclusive_scope']
  
  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



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

def with_scope options = {}, &block
  raise "exclusive scope already applied, can't apply it twice!" if Thread.current['mm_with_exclusive_scope']
  
  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