Class: MongoidTraffic::Logger
- Inherits:
-
Object
- Object
- MongoidTraffic::Logger
- Defined in:
- lib/mongoid_traffic/logger.rb
Instance Attribute Summary collapse
-
#additonal_counters ⇒ Object
Returns the value of attribute additonal_counters.
-
#log_cls ⇒ Object
Returns the value of attribute log_cls.
-
#selector ⇒ Object
Returns the value of attribute selector.
-
#time_scope ⇒ Object
Returns the value of attribute time_scope.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(log_cls, options = {}) ⇒ Logger
constructor
A new instance of Logger.
- #log ⇒ Object
Constructor Details
#initialize(log_cls, options = {}) ⇒ Logger
Returns a new instance of Logger.
12 13 14 15 16 17 18 19 |
# File 'lib/mongoid_traffic/logger.rb', line 12 def initialize(log_cls, = {}) @log_cls = log_cls @selector = log_cls.criteria.selector @time_scope = .fetch(:time_scope, TIME_SCOPE_OPTIONS.keys) @additonal_counters = .except(:time_scope, :scope) raise "Invalid time scope definition: #{time_scope}" unless time_scope.all? { |ts| TIME_SCOPE_OPTIONS.key?(ts) } end |
Instance Attribute Details
#additonal_counters ⇒ Object
Returns the value of attribute additonal_counters.
6 7 8 |
# File 'lib/mongoid_traffic/logger.rb', line 6 def additonal_counters @additonal_counters end |
#log_cls ⇒ Object
Returns the value of attribute log_cls.
3 4 5 |
# File 'lib/mongoid_traffic/logger.rb', line 3 def log_cls @log_cls end |
#selector ⇒ Object
Returns the value of attribute selector.
4 5 6 |
# File 'lib/mongoid_traffic/logger.rb', line 4 def selector @selector end |
#time_scope ⇒ Object
Returns the value of attribute time_scope.
5 6 7 |
# File 'lib/mongoid_traffic/logger.rb', line 5 def time_scope @time_scope end |
Class Method Details
.log(log_cls, *args) ⇒ Object
8 9 10 |
# File 'lib/mongoid_traffic/logger.rb', line 8 def self.log(log_cls, *args) new(log_cls, *args).log end |
Instance Method Details
#log ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/mongoid_traffic/logger.rb', line 21 def log time_scope.each do |ts| log_cls.collection .find(find_query(ts)) .update_many(upsert_query(ts), upsert: true) end end |