rack-analytics 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +6 -16
- data/README.markdown +16 -4
- data/lib/generators/rack/analytics/install_generator.rb +14 -0
- data/lib/generators/rack/analytics/templates/rack-analytics.rb +16 -0
- data/lib/rack/analytics.rb +6 -1
- data/lib/rack/analytics/version.rb +1 -1
- data/test.watchr +4 -0
- data/test/rack-analytics_test.rb +19 -0
- data/test/request_logger_test.rb +3 -8
- metadata +11 -6
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rack-analytics (0.0.
|
4
|
+
rack-analytics (0.0.2)
|
5
5
|
activesupport
|
6
6
|
bson_ext
|
7
7
|
mongo
|
@@ -10,12 +10,11 @@ PATH
|
|
10
10
|
GEM
|
11
11
|
remote: http://rubygems.org/
|
12
12
|
specs:
|
13
|
-
activesupport (3.0.
|
14
|
-
bson (1.2.
|
15
|
-
bson_ext (1.2.
|
16
|
-
mongo (1.2.
|
17
|
-
bson (>= 1.2.
|
18
|
-
nokogiri (1.4.4)
|
13
|
+
activesupport (3.0.4)
|
14
|
+
bson (1.2.2)
|
15
|
+
bson_ext (1.2.2)
|
16
|
+
mongo (1.2.2)
|
17
|
+
bson (>= 1.2.2)
|
19
18
|
rack (1.2.1)
|
20
19
|
rack-test (0.5.7)
|
21
20
|
rack (>= 1.0)
|
@@ -28,21 +27,12 @@ GEM
|
|
28
27
|
tilt (~> 1.2)
|
29
28
|
term-ansicolor (1.0.5)
|
30
29
|
tilt (1.2.1)
|
31
|
-
webrat (0.7.3)
|
32
|
-
nokogiri (>= 1.2.0)
|
33
|
-
rack (>= 1.0)
|
34
|
-
rack-test (>= 0.5.3)
|
35
30
|
|
36
31
|
PLATFORMS
|
37
32
|
ruby
|
38
33
|
|
39
34
|
DEPENDENCIES
|
40
|
-
activesupport
|
41
|
-
bson_ext
|
42
|
-
mongo
|
43
|
-
rack
|
44
35
|
rack-analytics!
|
45
36
|
rack-test
|
46
37
|
riot
|
47
38
|
sinatra
|
48
|
-
webrat
|
data/README.markdown
CHANGED
@@ -4,9 +4,21 @@
|
|
4
4
|
|
5
5
|
All requests are created on a separated thread, so it won't add a lot of overhead on each requests.
|
6
6
|
|
7
|
-
##
|
7
|
+
## Installation on Rails 3 ##
|
8
8
|
|
9
|
-
|
9
|
+
Add this line on your `Gemfile`:
|
10
|
+
|
11
|
+
gem 'rack-analytics'
|
12
|
+
|
13
|
+
Run `rails generate rack:analytics:install` to install the initializer file on `config/initializers/rack-analytics.rb`. Some configuration options are highlighted on this file.
|
14
|
+
|
15
|
+
Then, on your `config/application.rb`, add the following line after inside your Application class:
|
16
|
+
|
17
|
+
config.middlewares.insert_after Rack::Lock, Rack::Analytics::RequestLogger
|
18
|
+
|
19
|
+
## Installation on another Rack applications ##
|
20
|
+
|
21
|
+
If you're using Bundler, you can add this line on your `Gemfile`:
|
10
22
|
|
11
23
|
gem 'rack-analytics'
|
12
24
|
|
@@ -72,7 +84,7 @@ The env is a hash with all the parameters of the request, and the data is the fi
|
|
72
84
|
* Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
73
85
|
* Send me a pull request. Bonus points for topic branches.
|
74
86
|
|
75
|
-
##
|
87
|
+
## License ##
|
76
88
|
|
77
89
|
Copyright (c) 2011, Cainã Costa <cainan.costa@gmail.com>
|
78
90
|
|
@@ -84,4 +96,4 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH RE
|
|
84
96
|
|
85
97
|
Those are the people that helped me with this project, both with code and/or with guidance. Put your name here if you create a pull request and think you deserves it!
|
86
98
|
|
87
|
-
* Rafael França <rafael.ufs@gmail.com>
|
99
|
+
* Rafael França <rafael.ufs@gmail.com>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Rack
|
2
|
+
module Analytics
|
3
|
+
module Generators
|
4
|
+
class InstallGenerator < Rails::Generators::Base
|
5
|
+
desc "Copy rack-analytics default initializers"
|
6
|
+
source_root ::File.expand_path('../templates', __FILE__)
|
7
|
+
|
8
|
+
def copy_initializers
|
9
|
+
copy_file 'rack-analytics.rb', 'config/initializers/rack-analytics.rb'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# Config file for Rack::Analytics
|
2
|
+
|
3
|
+
Rack::Analytics.setup do |config|
|
4
|
+
# To change the database name only
|
5
|
+
# config.db_name = 'mydb'
|
6
|
+
|
7
|
+
# To change the database connection completely
|
8
|
+
# config.db = Mongo::Connection.new.db 'mydb'
|
9
|
+
|
10
|
+
# Parser configuration
|
11
|
+
# When this is active, only those fields will be logged
|
12
|
+
# config.parser.only = ['time', 'path', 'user_agent', 'referral']
|
13
|
+
|
14
|
+
# The fields that shouldn't be parsed
|
15
|
+
# config.parser.except = nil
|
16
|
+
end
|
data/lib/rack/analytics.rb
CHANGED
@@ -2,6 +2,7 @@ require 'rack/analytics/request_logger'
|
|
2
2
|
require 'rack/analytics/request_parser'
|
3
3
|
|
4
4
|
require 'active_support/core_ext/module/attribute_accessors'
|
5
|
+
require 'mongo'
|
5
6
|
|
6
7
|
module Rack
|
7
8
|
module Analytics
|
@@ -33,5 +34,9 @@ module Rack
|
|
33
34
|
|
34
35
|
thread
|
35
36
|
end
|
37
|
+
|
38
|
+
def self.setup
|
39
|
+
yield self
|
40
|
+
end
|
36
41
|
end
|
37
|
-
end
|
42
|
+
end
|
data/test.watchr
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'teststrap'
|
2
|
+
|
3
|
+
context Rack::Analytics do
|
4
|
+
context "it should change configuration when setup'ing" do
|
5
|
+
helper(:object) { Object.new }
|
6
|
+
|
7
|
+
context "db_name" do
|
8
|
+
setup do
|
9
|
+
Rack::Analytics.setup do |config|
|
10
|
+
config.db_name = "foo"
|
11
|
+
end
|
12
|
+
|
13
|
+
Rack::Analytics
|
14
|
+
end
|
15
|
+
|
16
|
+
asserts('should set db name correctly') { topic.db_name }.equals "foo"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/test/request_logger_test.rb
CHANGED
@@ -55,16 +55,11 @@ context "Rack::Analytics::RequestLogger" do
|
|
55
55
|
asserts("counter hasn't incremented") { db['views'].count }.equals 0
|
56
56
|
end
|
57
57
|
|
58
|
-
context "should save the path of the access" do
|
59
|
-
setup { get '/' }
|
60
|
-
|
61
|
-
asserts('it should have a time key') { db['views'].find_one }.includes 'path'
|
62
|
-
asserts('it should have a time set') { db['views'].find_one['path'] }.equals '/'
|
63
|
-
end
|
64
|
-
|
65
|
-
context "should save the time of the access" do
|
58
|
+
context "should save the path and the time of the access" do
|
66
59
|
setup { get '/' }
|
67
60
|
|
61
|
+
asserts('it should have a path key') { db['views'].find_one }.includes 'path'
|
62
|
+
asserts('it should have a path set') { db['views'].find_one['path'] }.equals '/'
|
68
63
|
asserts('it should have a time key') { db['views'].find_one }.includes 'time'
|
69
64
|
asserts('it should have a time set') { db['views'].find_one['time'] }.kind_of Time
|
70
65
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-analytics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 25
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "Cain\xC3\xA3 Costa"
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-02-
|
18
|
+
date: 2011-02-19 00:00:00 -02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -131,12 +131,16 @@ files:
|
|
131
131
|
- Gemfile.lock
|
132
132
|
- README.markdown
|
133
133
|
- Rakefile
|
134
|
+
- lib/generators/rack/analytics/install_generator.rb
|
135
|
+
- lib/generators/rack/analytics/templates/rack-analytics.rb
|
134
136
|
- lib/rack-analytics.rb
|
135
137
|
- lib/rack/analytics.rb
|
136
138
|
- lib/rack/analytics/request_logger.rb
|
137
139
|
- lib/rack/analytics/request_parser.rb
|
138
140
|
- lib/rack/analytics/version.rb
|
139
141
|
- rack-analytics.gemspec
|
142
|
+
- test.watchr
|
143
|
+
- test/rack-analytics_test.rb
|
140
144
|
- test/request_logger_test.rb
|
141
145
|
- test/request_parser_test.rb
|
142
146
|
- test/support/dummy_app.rb
|
@@ -172,11 +176,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
172
176
|
requirements: []
|
173
177
|
|
174
178
|
rubyforge_project: rack-analytics
|
175
|
-
rubygems_version: 1.
|
179
|
+
rubygems_version: 1.5.2
|
176
180
|
signing_key:
|
177
181
|
specification_version: 3
|
178
182
|
summary: A rack middleware that collects access statistics
|
179
183
|
test_files:
|
184
|
+
- test/rack-analytics_test.rb
|
180
185
|
- test/request_logger_test.rb
|
181
186
|
- test/request_parser_test.rb
|
182
187
|
- test/support/dummy_app.rb
|