Module: Headcount
- Includes:
- History
- Defined in:
- lib/headcount.rb,
lib/headcount/runner.rb,
lib/headcount/history.rb,
lib/headcount/railtie.rb,
lib/headcount/support.rb,
lib/headcount/version.rb,
lib/headcount/registry.rb,
lib/headcount/exceptions.rb,
lib/headcount/persistence.rb,
lib/headcount/configuration.rb,
lib/headcount/persistence/file.rb
Defined Under Namespace
Modules: Configuration, History, Persistence, Runner, Support
Classes: Railtie, Registry, UnknownKey, UnsupportedQuery
Constant Summary
collapse
- VERSION =
"0.7.1"
- @@registry =
Headcount::Registry.new
- @@config =
nil
Class Method Summary
collapse
Class Method Details
9
10
11
|
# File 'lib/headcount/configuration.rb', line 9
def configure(&block)
settings.evaluate(&block)
end
|
.count(arg = nil) ⇒ Object
this method is getting a little messy – need to clean it up arg can either be a symbol or a time instance
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/headcount.rb', line 26
def count(arg = nil)
if arg.is_a?(Symbol)
key = arg
count_for(key)
else
{}.tap do |headcount|
now = DateTime.now
time = arg || now
headcount[:timestamp] = Headcount::Support.timestamp_for(time)
@@registry.each do |key, query| query = query_for_time(query, time) unless time == now
query = yield query if block_given?
headcount[key] = query.count
end
end
end
end
|
.count! ⇒ Object
46
47
48
49
50
|
# File 'lib/headcount.rb', line 46
def count!
count.tap do |headcount|
persist(headcount)
end
end
|
.find(key) ⇒ Object
20
21
22
|
# File 'lib/headcount.rb', line 20
def find(key)
@@registry[key.to_sym]
end
|
.register(key, query) ⇒ Object
14
15
16
17
18
|
# File 'lib/headcount.rb', line 14
def register(key, query)
key.to_sym.tap do |key|
@@registry[key] = query
end
end
|
.reset ⇒ Object
52
53
54
55
|
# File 'lib/headcount.rb', line 52
def reset
reset_registry
reset_settings
end
|
.reset_registry ⇒ Object
58
59
60
|
# File 'lib/headcount.rb', line 58
def reset_registry
@@registry.clear
end
|
.settings ⇒ Object
5
6
7
|
# File 'lib/headcount/configuration.rb', line 5
def settings
@@config ||= Configuration::Base.new
end
|