Class: Mongoid::Report::ScopeCollection
- Inherits:
-
Struct
- Object
- Struct
- Mongoid::Report::ScopeCollection
- Defined in:
- lib/mongoid/report/scope_collection.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
Returns the value of attribute context.
Instance Method Summary collapse
- #all ⇒ Object
- #in_batches(conditions) ⇒ Object
-
#initialize(context) ⇒ ScopeCollection
constructor
A new instance of ScopeCollection.
- #query(conditions = {}) ⇒ Object
- #scopes ⇒ Object
- #yield ⇒ Object
Constructor Details
#initialize(context) ⇒ ScopeCollection
Returns a new instance of ScopeCollection.
7 8 9 10 |
# File 'lib/mongoid/report/scope_collection.rb', line 7 def initialize(context) @mutex = Mutex.new super end |
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context
6 7 8 |
# File 'lib/mongoid/report/scope_collection.rb', line 6 def context @context end |
Instance Method Details
#all ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/mongoid/report/scope_collection.rb', line 43 def all Hash.new { |h, k| h[k] = {} }.tap do |hash| if Mongoid::Report::Config.use_threads_on_aggregate scopes.map do |scope| Thread.new do rows = scope.all @mutex.synchronize do hash[scope.report_module][scope.report_name] = rows end end end.map(&:join) else scopes.each do |scope| hash[scope.report_module][scope.report_name] = scope.all end end end end |
#in_batches(conditions) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/mongoid/report/scope_collection.rb', line 36 def in_batches(conditions) scopes.each do |scope| scope.in_batches(conditions) end self end |
#query(conditions = {}) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/mongoid/report/scope_collection.rb', line 22 def query(conditions = {}) scopes.each do |scope| scope.query(conditions) end self end |
#scopes ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/mongoid/report/scope_collection.rb', line 12 def scopes @scopes ||= [].tap do |collection| context.settings.each do |report_module, module_settings| module_settings[:reports].each do |report_name, _report_settings| collection << Scope.new(context, report_module, report_name) end end end end |
#yield ⇒ Object
29 30 31 32 33 34 |
# File 'lib/mongoid/report/scope_collection.rb', line 29 def yield scopes.each do |scope| scope.yield end self end |