Module: Minuteman
- Defined in:
- lib/minuteman.rb,
lib/minuteman/user.rb,
lib/minuteman/event.rb,
lib/minuteman/model.rb,
lib/minuteman/result.rb,
lib/minuteman/counter.rb,
lib/minuteman/analyzer.rb,
lib/minuteman/analyzable.rb,
lib/minuteman/configuration.rb
Defined Under Namespace
Modules: Analyzable
Classes: Analyzer, Configuration, Counter, Event, Model, Result, User
Constant Summary
collapse
- LUA_CACHE =
Hash.new { |h, k| h[k] = Hash.new }
- LUA_OPERATIONS =
File.expand_path("../minuteman/lua/operations.lua", __FILE__)
Class Method Summary
collapse
Class Method Details
.add(action, time = Time.now.utc, users = []) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/minuteman.rb', line 51
def add(action, time = Time.now.utc, users = [])
time_spans.each do |time_span|
process do
counter = Minuteman::Counter.create({
type: action,
time: patterns[time_span].call(time)
})
counter.incr
end
end
Array(users).each do |user|
time_spans.each do |time_span|
counter = Minuteman::Counter::User.create({
user_id: user.id,
type: action,
time: patterns[time_span].call(time)
})
counter.incr
end
end
end
|
.analyze(action) ⇒ Object
76
77
78
|
# File 'lib/minuteman.rb', line 76
def analyze(action)
analyzers_cache[action]
end
|
.config ⇒ Object
8
9
10
|
# File 'lib/minuteman.rb', line 8
def config
@_configuration ||= Configuration.new
end
|
12
13
14
|
# File 'lib/minuteman.rb', line 12
def configure
yield(config)
end
|
.count(action) ⇒ Object
80
81
82
|
# File 'lib/minuteman.rb', line 80
def count(action)
counters_cache[action]
end
|
.events ⇒ Object
28
29
30
|
# File 'lib/minuteman.rb', line 28
def events
config.redis.call("SMEMBERS", "#{Minuteman.prefix}::Events")
end
|
.patterns ⇒ Object
20
21
22
|
# File 'lib/minuteman.rb', line 20
def patterns
config.patterns
end
|
.prefix ⇒ Object
16
17
18
|
# File 'lib/minuteman.rb', line 16
def prefix
config.prefix
end
|
.time_spans ⇒ Object
24
25
26
|
# File 'lib/minuteman.rb', line 24
def time_spans
@_time_spans = patterns.keys
end
|
.track(action, users = nil, time = Time.now.utc) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/minuteman.rb', line 32
def track(action, users = nil, time = Time.now.utc)
users = Minuteman::User.create if users.nil?
Array(users).each do |user|
process do
time_spans.each do |time_span|
event = Minuteman::Event.find_or_create(
type: action,
time: patterns[time_span].call(time)
)
event.setbit(user.id)
end
end
end
users
end
|