tophold_rack 0.1.1 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile +4 -0
- data/lib/generators/tophold_rack/templates/tophold_rack.rb +6 -2
- data/lib/tophold_rack/engine.rb +8 -2
- data/lib/tophold_rack/redispatcher.rb +13 -6
- data/lib/tophold_rack/version.rb +1 -1
- data/lib/tophold_rack.rb +2 -0
- metadata +3 -4
- data/.rvmrc +0 -1
data/.gitignore
CHANGED
data/Gemfile
CHANGED
@@ -43,8 +43,12 @@ Rails.configuration.tophold_rack_devise_scope = "user"
|
|
43
43
|
#customize this to meet your requirments.
|
44
44
|
Rails.configuration.tophold_rack_request_black_list << "admin"
|
45
45
|
|
46
|
-
#
|
47
|
-
|
46
|
+
#track redis settings
|
47
|
+
redis = Redis.new host: "127.0.0.1", port: 6379
|
48
|
+
space = Redis::Namespace.new 'st', redis: redis
|
49
|
+
Rails.configuration.tophold_statistics_redis = space
|
50
|
+
|
51
|
+
Rails.configuration.tophold_statistics_queue = "static"
|
48
52
|
|
49
53
|
#if Rails.env.development?
|
50
54
|
# Rails.configuration.tophold_rack_disabled = true
|
data/lib/tophold_rack/engine.rb
CHANGED
@@ -6,9 +6,15 @@ module TopholdRack
|
|
6
6
|
|
7
7
|
config.tophold_rack_request_black_list = ["uploads", "assets"]
|
8
8
|
|
9
|
-
config.tophold_rack_tracking_url = "http://localhost:8888/tracking/"
|
10
|
-
|
11
9
|
config.tophold_rack_disabled = false
|
10
|
+
|
11
|
+
redis = Redis.new host: "127.0.0.1", port: 6379
|
12
|
+
|
13
|
+
nspace = Redis::Namespace.new 'st', redis: redis
|
14
|
+
|
15
|
+
config.tophold_statistics_redis = nspace
|
16
|
+
|
17
|
+
config.tophold_statistics_queue = "static"
|
12
18
|
|
13
19
|
initializer "tophold_rack.load_app_instance_data" do |app|
|
14
20
|
TopholdRack.setup do |config|
|
@@ -7,6 +7,7 @@ module TopholdRack
|
|
7
7
|
|
8
8
|
def initialize app
|
9
9
|
@app = app
|
10
|
+
@redis = Rails.configuration.tophold_statistics_redis
|
10
11
|
end
|
11
12
|
|
12
13
|
def request_black_list
|
@@ -18,12 +19,18 @@ module TopholdRack
|
|
18
19
|
request = Rack::Request.new env
|
19
20
|
if request.get?
|
20
21
|
path, query = request.path, request.query_string
|
21
|
-
scope = env["rack.session"]["warden.user.#{Rails.configuration.tophold_rack_devise_scope}.key"]
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
if scope = env["rack.session"]["warden.user.#{Rails.configuration.tophold_rack_devise_scope}.key"]
|
23
|
+
user_id = scope[1][0].to_s =~ /\d+/ ? scope[1][0] : scope[0][0]
|
24
|
+
else
|
25
|
+
user_id = nil
|
26
|
+
end
|
27
|
+
unless path =~ request_black_list
|
28
|
+
begin
|
29
|
+
@redis.lpush(Rails.configuration.tophold_statistics_queue,{user_id: user_id, url: path, visited_date: Date.today}.to_json)
|
30
|
+
rescue Exception => e
|
31
|
+
raise e
|
32
|
+
Rails.logger.fatal 'RedisDispatcher can not work!'
|
33
|
+
end
|
27
34
|
end
|
28
35
|
end
|
29
36
|
end
|
data/lib/tophold_rack/version.rb
CHANGED
data/lib/tophold_rack.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tophold_rack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-08-19 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A rack based middleware to redispatch requested uri path to 3rd party
|
15
15
|
tracking server
|
@@ -20,7 +20,6 @@ extensions: []
|
|
20
20
|
extra_rdoc_files: []
|
21
21
|
files:
|
22
22
|
- .gitignore
|
23
|
-
- .rvmrc
|
24
23
|
- Gemfile
|
25
24
|
- LICENSE.txt
|
26
25
|
- README.md
|
@@ -52,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
52
51
|
version: '0'
|
53
52
|
requirements: []
|
54
53
|
rubyforge_project:
|
55
|
-
rubygems_version: 1.8.
|
54
|
+
rubygems_version: 1.8.25
|
56
55
|
signing_key:
|
57
56
|
specification_version: 3
|
58
57
|
summary: A rack based middleware to redispatch requested uri path to 3rd party tracking
|
data/.rvmrc
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
rvm use ruby-1.9.3-p362@tophold_rack
|