Class: Mongoid::Tracking::TrackerAggregates

Inherits:
Object
  • Object
show all
Defined in:
lib/mongoid/tracking/tracker_aggregates.rb

Overview

This internal class handles all interaction of an aggregation token.

Instance Method Summary collapse

Constructor Details

#initialize(owner, token, key_selector, track_field = nil) ⇒ TrackerAggregates

Returns a new instance of TrackerAggregates.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/mongoid/tracking/tracker_aggregates.rb', line 7

def initialize(owner, token, key_selector, track_field = nil)
  @owner, @token = owner, token
  @key = key_selector.first
  @track_field = track_field

  @accessor = @owner.class.send(:internal_accessor_name, @token)
  @selector = { ns: @token }
  @selector.merge!(key: @key) if @key

  @criteria = @owner.send(@accessor).where(@selector)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object

Delegate all missing methods to the underlying Mongoid Criteria



20
21
22
# File 'lib/mongoid/tracking/tracker_aggregates.rb', line 20

def method_missing(name, *args, &block)
  @criteria.send(name)
end