headcount 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/Gemfile +3 -0
  2. data/Gemfile.lock +140 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +3 -0
  5. data/Rakefile +1 -0
  6. data/lib/headcount.rb +55 -0
  7. data/lib/headcount/api.rb +11 -0
  8. data/lib/headcount/configuration.rb +48 -0
  9. data/lib/headcount/exceptions.rb +7 -0
  10. data/lib/headcount/persistence.rb +10 -0
  11. data/lib/headcount/persistence/file.rb +16 -0
  12. data/lib/headcount/railtie.rb +7 -0
  13. data/lib/headcount/registry.rb +10 -0
  14. data/lib/headcount/runner.rb +4 -0
  15. data/lib/headcount/support.rb +28 -0
  16. data/lib/headcount/version.rb +3 -0
  17. data/lib/tasks/headcount_tasks.rake +4 -0
  18. data/spec/dummy/README.rdoc +261 -0
  19. data/spec/dummy/Rakefile +7 -0
  20. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  21. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  22. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  23. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  24. data/spec/dummy/app/models/user.rb +2 -0
  25. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  26. data/spec/dummy/config.ru +4 -0
  27. data/spec/dummy/config/application.rb +62 -0
  28. data/spec/dummy/config/boot.rb +10 -0
  29. data/spec/dummy/config/database.yml +25 -0
  30. data/spec/dummy/config/environment.rb +5 -0
  31. data/spec/dummy/config/environments/development.rb +37 -0
  32. data/spec/dummy/config/environments/production.rb +67 -0
  33. data/spec/dummy/config/environments/test.rb +37 -0
  34. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  35. data/spec/dummy/config/initializers/headcount.rb +15 -0
  36. data/spec/dummy/config/initializers/inflections.rb +15 -0
  37. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  38. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  39. data/spec/dummy/config/initializers/session_store.rb +8 -0
  40. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  41. data/spec/dummy/config/locales/en.yml +5 -0
  42. data/spec/dummy/config/routes.rb +58 -0
  43. data/spec/dummy/db/development.sqlite3 +0 -0
  44. data/spec/dummy/db/migrate/20120406005419_add_users.rb +7 -0
  45. data/spec/dummy/db/schema.rb +20 -0
  46. data/spec/dummy/db/test.sqlite3 +0 -0
  47. data/spec/dummy/log/development.log +21 -0
  48. data/spec/dummy/log/test.log +858 -0
  49. data/spec/dummy/public/404.html +26 -0
  50. data/spec/dummy/public/422.html +26 -0
  51. data/spec/dummy/public/500.html +25 -0
  52. data/spec/dummy/public/favicon.ico +0 -0
  53. data/spec/dummy/script/rails +6 -0
  54. data/spec/models/api_spec.rb +71 -0
  55. data/spec/models/configuration_spec.rb +28 -0
  56. data/spec/models/persistence_spec.rb +33 -0
  57. data/spec/spec_helper.rb +23 -0
  58. data/spec/tmp/headcount.json +3 -0
  59. metadata +228 -0
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ </div>
24
+ </body>
25
+ </html>
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,71 @@
1
+ require 'spec_helper'
2
+
3
+ describe Headcount do
4
+ before(:each) do
5
+ Headcount.reset
6
+ end
7
+
8
+ describe '.find' do
9
+ context 'when the key is unknown' do
10
+ it 'should simply return nil' do
11
+ Headcount.find(:missing).should be_nil
12
+ end
13
+ end
14
+ end
15
+
16
+ describe '.reset' do
17
+ it 'should remove all registered keys' do
18
+ Headcount.register(:users, User)
19
+ Headcount.reset
20
+ Headcount.find(:users).should be_nil
21
+ end
22
+ end
23
+
24
+ describe '.register' do
25
+ let(:query) { User.where(true) }
26
+
27
+ it 'should register the query for the given key' do
28
+ Headcount.register(:users, query)
29
+ Headcount.find(:users).should eq(query)
30
+ end
31
+
32
+ it 'should return the registered key' do
33
+ Headcount.register(:users, query).should eq(:users)
34
+ end
35
+
36
+ it 'should always return the key as a symbol' do
37
+ Headcount.register("users", query).should eq(:users)
38
+ end
39
+ end
40
+
41
+ describe '.registry' do
42
+ it 'should not be publicly accessible' do
43
+ lambda { Headcount.registry }.should raise_error(NoMethodError)
44
+ end
45
+ end
46
+
47
+ describe '.count' do
48
+ context 'when called without arguments' do
49
+ it 'returns the results as a hash' do
50
+ Headcount.register(:users, User)
51
+ Headcount.count.should eq({:users => User.count})
52
+ end
53
+ end
54
+
55
+ context 'when given a key' do
56
+ context 'and the key is registered' do
57
+ it 'returns the count for the registered key' do
58
+ Headcount.register(:users, User)
59
+ Headcount.count(:users).should eq(User.count)
60
+ end
61
+ end
62
+
63
+ context 'and the key is unknown' do
64
+ it 'raises a Headcount::UnknownKey error' do
65
+ lambda { Headcount.count(:missing) }.should raise_error(Headcount::UnknownKey)
66
+ end
67
+ end
68
+
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Headcount::Configuration do
4
+ let(:config) { Headcount.configure }
5
+
6
+ describe '#count' do
7
+ it 'should return the registration key' do
8
+ config.count(User).should eq(:users)
9
+ end
10
+
11
+ it 'should add the given query to the registry' do
12
+ Headcount.find(config.count(User)).should eq(User)
13
+ end
14
+
15
+ context 'when key is given' do
16
+ it 'should override the default key' do
17
+ config.count(User, :as => :members)
18
+ Headcount.find(:members).should eq(User)
19
+ end
20
+ end
21
+
22
+ context 'when a bad query is given' do
23
+ it 'throws a Headcount::UnsupportedQuery error' do
24
+ lambda { config.count(Object) }.should raise_error(Headcount::UnsupportedQuery)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ # has to be defined as a contant or won't be available in configure block
4
+ PATH = 'spec/tmp/headcount.json'
5
+
6
+ describe Headcount do
7
+ before(:each) do
8
+ Headcount.configure do |config|
9
+ config.path = PATH
10
+ config.count User
11
+ end
12
+
13
+ File.delete(PATH) if File.exists?(PATH)
14
+ end
15
+
16
+ describe '.count!' do
17
+ # right now a json file is the only supported form of persistence
18
+ it 'writes the current headcount out to the persistence layer' do
19
+ Headcount.count!
20
+ File.exists?(PATH).should be_true
21
+ end
22
+
23
+ it 'appends to the existing contents' do
24
+ 3.times do
25
+ Headcount.count!
26
+ end
27
+
28
+ File.open(PATH, 'r') do |file|
29
+ file.readlines.should have(3).items
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,23 @@
1
+ require 'rubygems'
2
+ require 'spork'
3
+ #uncomment the following line to use spork with the debugger
4
+ #require 'spork/ext/ruby-debug'
5
+
6
+ Spork.prefork do
7
+ ENV["RAILS_ENV"] ||= 'test'
8
+ require File.expand_path("../dummy/config/environment", __FILE__)
9
+ require 'rspec/rails'
10
+ require 'rspec/autorun'
11
+
12
+ Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
13
+
14
+ RSpec.configure do |config|
15
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
16
+ config.use_transactional_fixtures = true
17
+ config.infer_base_class_for_anonymous_controllers = false
18
+ end
19
+ end
20
+
21
+ Spork.each_run do
22
+ # This code will be run each time you run your specs.
23
+ end
@@ -0,0 +1,3 @@
1
+ {"users":0,"members":0}
2
+ {"users":0,"members":0}
3
+ {"users":0,"members":0}
metadata ADDED
@@ -0,0 +1,228 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: headcount
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Ryan Mohr
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2012-04-06 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rails
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 3.2.2
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: sqlite3
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ type: :development
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec-rails
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ type: :development
47
+ version_requirements: *id003
48
+ - !ruby/object:Gem::Dependency
49
+ name: capybara
50
+ prerelease: false
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ type: :development
58
+ version_requirements: *id004
59
+ - !ruby/object:Gem::Dependency
60
+ name: spork
61
+ prerelease: false
62
+ requirement: &id005 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ type: :development
69
+ version_requirements: *id005
70
+ - !ruby/object:Gem::Dependency
71
+ name: guard-rspec
72
+ prerelease: false
73
+ requirement: &id006 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ type: :development
80
+ version_requirements: *id006
81
+ - !ruby/object:Gem::Dependency
82
+ name: guard-spork
83
+ prerelease: false
84
+ requirement: &id007 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: "0"
90
+ type: :development
91
+ version_requirements: *id007
92
+ description: ""
93
+ email:
94
+ - ryan.mohr@gmail.com
95
+ executables: []
96
+
97
+ extensions: []
98
+
99
+ extra_rdoc_files: []
100
+
101
+ files:
102
+ - lib/headcount/api.rb
103
+ - lib/headcount/configuration.rb
104
+ - lib/headcount/exceptions.rb
105
+ - lib/headcount/persistence/file.rb
106
+ - lib/headcount/persistence.rb
107
+ - lib/headcount/railtie.rb
108
+ - lib/headcount/registry.rb
109
+ - lib/headcount/runner.rb
110
+ - lib/headcount/support.rb
111
+ - lib/headcount/version.rb
112
+ - lib/headcount.rb
113
+ - lib/tasks/headcount_tasks.rake
114
+ - MIT-LICENSE
115
+ - Gemfile
116
+ - Gemfile.lock
117
+ - Rakefile
118
+ - README.rdoc
119
+ - spec/dummy/app/assets/javascripts/application.js
120
+ - spec/dummy/app/assets/stylesheets/application.css
121
+ - spec/dummy/app/controllers/application_controller.rb
122
+ - spec/dummy/app/helpers/application_helper.rb
123
+ - spec/dummy/app/models/user.rb
124
+ - spec/dummy/app/views/layouts/application.html.erb
125
+ - spec/dummy/config/application.rb
126
+ - spec/dummy/config/boot.rb
127
+ - spec/dummy/config/database.yml
128
+ - spec/dummy/config/environment.rb
129
+ - spec/dummy/config/environments/development.rb
130
+ - spec/dummy/config/environments/production.rb
131
+ - spec/dummy/config/environments/test.rb
132
+ - spec/dummy/config/initializers/backtrace_silencers.rb
133
+ - spec/dummy/config/initializers/headcount.rb
134
+ - spec/dummy/config/initializers/inflections.rb
135
+ - spec/dummy/config/initializers/mime_types.rb
136
+ - spec/dummy/config/initializers/secret_token.rb
137
+ - spec/dummy/config/initializers/session_store.rb
138
+ - spec/dummy/config/initializers/wrap_parameters.rb
139
+ - spec/dummy/config/locales/en.yml
140
+ - spec/dummy/config/routes.rb
141
+ - spec/dummy/config.ru
142
+ - spec/dummy/db/development.sqlite3
143
+ - spec/dummy/db/migrate/20120406005419_add_users.rb
144
+ - spec/dummy/db/schema.rb
145
+ - spec/dummy/db/test.sqlite3
146
+ - spec/dummy/log/development.log
147
+ - spec/dummy/log/test.log
148
+ - spec/dummy/public/404.html
149
+ - spec/dummy/public/422.html
150
+ - spec/dummy/public/500.html
151
+ - spec/dummy/public/favicon.ico
152
+ - spec/dummy/Rakefile
153
+ - spec/dummy/README.rdoc
154
+ - spec/dummy/script/rails
155
+ - spec/models/api_spec.rb
156
+ - spec/models/configuration_spec.rb
157
+ - spec/models/persistence_spec.rb
158
+ - spec/spec_helper.rb
159
+ - spec/tmp/headcount.json
160
+ homepage: http://github.com/kumu/headcount
161
+ licenses: []
162
+
163
+ post_install_message:
164
+ rdoc_options: []
165
+
166
+ require_paths:
167
+ - lib
168
+ required_ruby_version: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: "0"
174
+ required_rubygems_version: !ruby/object:Gem::Requirement
175
+ none: false
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ version: "0"
180
+ requirements: []
181
+
182
+ rubyforge_project: headcount
183
+ rubygems_version: 1.8.21
184
+ signing_key:
185
+ specification_version: 3
186
+ summary: A simple stat collector for rails apps
187
+ test_files:
188
+ - spec/dummy/app/assets/javascripts/application.js
189
+ - spec/dummy/app/assets/stylesheets/application.css
190
+ - spec/dummy/app/controllers/application_controller.rb
191
+ - spec/dummy/app/helpers/application_helper.rb
192
+ - spec/dummy/app/models/user.rb
193
+ - spec/dummy/app/views/layouts/application.html.erb
194
+ - spec/dummy/config/application.rb
195
+ - spec/dummy/config/boot.rb
196
+ - spec/dummy/config/database.yml
197
+ - spec/dummy/config/environment.rb
198
+ - spec/dummy/config/environments/development.rb
199
+ - spec/dummy/config/environments/production.rb
200
+ - spec/dummy/config/environments/test.rb
201
+ - spec/dummy/config/initializers/backtrace_silencers.rb
202
+ - spec/dummy/config/initializers/headcount.rb
203
+ - spec/dummy/config/initializers/inflections.rb
204
+ - spec/dummy/config/initializers/mime_types.rb
205
+ - spec/dummy/config/initializers/secret_token.rb
206
+ - spec/dummy/config/initializers/session_store.rb
207
+ - spec/dummy/config/initializers/wrap_parameters.rb
208
+ - spec/dummy/config/locales/en.yml
209
+ - spec/dummy/config/routes.rb
210
+ - spec/dummy/config.ru
211
+ - spec/dummy/db/development.sqlite3
212
+ - spec/dummy/db/migrate/20120406005419_add_users.rb
213
+ - spec/dummy/db/schema.rb
214
+ - spec/dummy/db/test.sqlite3
215
+ - spec/dummy/log/development.log
216
+ - spec/dummy/log/test.log
217
+ - spec/dummy/public/404.html
218
+ - spec/dummy/public/422.html
219
+ - spec/dummy/public/500.html
220
+ - spec/dummy/public/favicon.ico
221
+ - spec/dummy/Rakefile
222
+ - spec/dummy/README.rdoc
223
+ - spec/dummy/script/rails
224
+ - spec/models/api_spec.rb
225
+ - spec/models/configuration_spec.rb
226
+ - spec/models/persistence_spec.rb
227
+ - spec/spec_helper.rb
228
+ - spec/tmp/headcount.json