From 6c0d6751b3f71b78d9316286085c21ab32fd4fd4 Mon Sep 17 00:00:00 2001 From: Tim Friedrich Date: Fri, 17 Feb 2017 15:38:43 +0100 Subject: [PATCH] added functionality to only track, add for selected time_ranges --- lib/minuteman.rb | 10 +++++----- lib/minuteman/user.rb | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/minuteman.rb b/lib/minuteman.rb index 506281c..f99ee87 100644 --- a/lib/minuteman.rb +++ b/lib/minuteman.rb @@ -29,12 +29,12 @@ def events config.redis.call("SMEMBERS", "#{Minuteman.prefix}::Events") end - def track(action, users = nil, time = Time.now.utc) + def track(action, users = nil, time = Time.now.utc, times = time_spans) users = Minuteman::User.create if users.nil? Array(users).each do |user| process do - time_spans.each do |time_span| + times.each do |time_span| event = Minuteman::Event.find_or_create( type: action, time: patterns[time_span].call(time) @@ -48,8 +48,8 @@ def track(action, users = nil, time = Time.now.utc) users end - def add(action, time = Time.now.utc, users = []) - time_spans.each do |time_span| + def add(action, time = Time.now.utc, users = [], times = time_spans) + times.each do |time_span| process do counter = Minuteman::Counter.create({ type: action, @@ -61,7 +61,7 @@ def add(action, time = Time.now.utc, users = []) end Array(users).each do |user| - time_spans.each do |time_span| + times.each do |time_span| counter = Minuteman::Counter::User.create({ user_id: user.id, type: action, diff --git a/lib/minuteman/user.rb b/lib/minuteman/user.rb index b7a5f55..9b9f115 100644 --- a/lib/minuteman/user.rb +++ b/lib/minuteman/user.rb @@ -18,12 +18,12 @@ def save super end - def track(action, time = Time.now.utc) - Minuteman.track(action, self, time) + def track(action, time = Time.now.utc, times = Minuteman.time_spans) + Minuteman.track(action, self, time, times) end - def add(action, time = Time.now.utc) - Minuteman.add(action, time, self) + def add(action, time = Time.now.utc, times = Minuteman.time_spans) + Minuteman.add(action, time, self, times) end def count(action, time = Time.now.utc)