Skip to content

Commit

Permalink
added functionality to only track, add for selected time_ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Friedrich committed Feb 17, 2017
1 parent 8358096 commit 6c0d675
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions lib/minuteman.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand All @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions lib/minuteman/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6c0d675

Please sign in to comment.