headcount 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- headcount (0.0.1)
4
+ headcount (0.6.0)
5
5
  rails (~> 3.2.2)
6
6
 
7
7
  GEM
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2012 YOURNAME
1
+ Copyright 2012 Ryan Mohr
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -33,6 +33,9 @@ Headcount.configure do |config|
33
33
 
34
34
  # you can specify the key yourself if you'd like to override the default
35
35
  count User.active, :as => :active_members
36
+
37
+ # if you're fine with using default keys you can pass a list of queries instead
38
+ count User, Account
36
39
  end
37
40
  ```
38
41
 
@@ -44,11 +47,13 @@ If you'd like to access or reconfigure Headcount outside of the initializer you
44
47
  # Usage
45
48
 
46
49
  Fire up `rails c` and run:
50
+
47
51
  ```
48
52
  Headcount.count # will return current headcount as a hash
49
53
  ```
50
54
 
51
55
  If you'd like to have the results written to disk instead just use the bang version:
56
+
52
57
  ```
53
58
  Headcount.count! # will append the results to the output file
54
59
  ```
@@ -59,7 +64,11 @@ Your options are open as far as scheduling goes. If you like [crontab](http://c
59
64
 
60
65
  You have two options for triggering a headcount.
61
66
 
62
- 1. Call `Headcount.count!` directly
63
- 2. Use `rake headcount`
67
+ 1. Call it directly: `Headcount.count!`
68
+ 2. Use the rake task: `rake headcount`
69
+
70
+ In the future I may write a daemon to simplify the scheduling process with an upstart script to boot, but for now you're on your own.
71
+
72
+ # Credit
64
73
 
65
- In the future I may write a daemon to simplify the scheduling process with an upstart script to boot, but for now you're on your own.
74
+ Headcount was created for use at Kumu (http://kumupowered.com)
@@ -34,17 +34,38 @@ module Headcount
34
34
  instance_exec(self, &block)
35
35
  end
36
36
 
37
- def count(query, options = {}, &block)
38
- raise UnsupportedQuery, 'query does not respond to :count' unless query.respond_to?(:count)
37
+ def count(*arguments, &block)
38
+ if list_given?(*arguments)
39
+ count_each(arguments.flatten)
40
+ else
41
+ query = arguments[0]
42
+ options = arguments[1] || {}
43
+
44
+ if query.respond_to?(:count)
45
+ key = options[:as] || Headcount::Support.key_for(query)
39
46
 
40
- key = options[:as] || Headcount::Support.key_for(query)
47
+ # just ignore blocks for now
48
+ # not really finding a need for nested declarations
49
+ #if block_given?
50
+ # evaluate(&block)
51
+ #end
41
52
 
42
- # just ignore blocks for now
43
- #if block_given?
44
- # evaluate(&block)
45
- #end
46
-
47
- Headcount.register(key, query)
53
+ Headcount.register(key, query)
54
+ else
55
+ raise UnsupportedQuery, 'query does not respond to :count'
56
+ end
57
+ end
58
+ end
59
+
60
+ private
61
+ def list_given?(*arguments)
62
+ arguments[0].is_a?(Array) || (arguments.length > 1 && !arguments[1].is_a?(Hash))
63
+ end
64
+
65
+ def count_each(queries)
66
+ queries.each do |query|
67
+ count(query)
68
+ end
48
69
  end
49
70
  end
50
71
  end
@@ -1,3 +1,3 @@
1
1
  module Headcount
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: headcount
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.5.0
5
+ version: 0.6.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ryan Mohr
@@ -89,7 +89,7 @@ dependencies:
89
89
  version: "0"
90
90
  type: :development
91
91
  version_requirements: *id007
92
- description: ""
92
+ description: If you can write a query for it, headcount can track it for you.
93
93
  email:
94
94
  - ryan.mohr@gmail.com
95
95
  executables: []
@@ -142,6 +142,6 @@ rubyforge_project: headcount
142
142
  rubygems_version: 1.8.21
143
143
  signing_key:
144
144
  specification_version: 3
145
- summary: A simple stat collector for rails apps
145
+ summary: A simple stat collector for rails apps.
146
146
  test_files: []
147
147