tophold_rack 0.0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,18 @@
1
- # TopholdRack
1
+ ## Scenario
2
2
 
3
- TODO: Write a gem description
3
+ Once you want to do some statistics on your ROR application, there're three solutions so far as I know.
4
+
5
+ * One is to analyze the log file(decouple way, but need to customize the log format to record who is the current user)
6
+ * The other way is add some callbacks in your code(coupled).
7
+ * And also you could use the google analytics(not so realtime).
8
+
9
+ Today I introduce you the way I do.
10
+
11
+ When we talk about how to authticate in rails, people may suggest you the very popular gem ``` devise ```, it's based on the ```warden``` middleware, and you can access the seeeion in your rack code.
12
+
13
+ Since with rack we could access the request info(path, query string etc) and we also could access the session info, why not we collect these info and parse it?
14
+
15
+ That's what tophold_rack do. Tophold rack will not perform *statistics* work, it only collect nessary info and send it to the 3rd party ( I coded this module with node, see detail at [here] (https://github.com/tteng/fetch_stock_quotes/blob/master/src/tracking_handler.coffee)
4
16
 
5
17
  ## Installation
6
18
 
@@ -16,9 +28,27 @@ Or install it yourself as:
16
28
 
17
29
  $ gem install tophold_rack
18
30
 
31
+ After installation, run
32
+
33
+ $ rails g tophold_rack install
34
+
35
+ to generate the config file.
36
+
19
37
  ## Usage
20
38
 
21
- TODO: Write usage instructions here
39
+ Say, if you authticate with admin_user.rb model, change the devise scope to corresponding model name.
40
+
41
+ Rails.configuration.tophold_rack_devise_scope = "admin_user"
42
+
43
+ Sometimes we don't want to analyze assets and some static file uri, it make no sense. You could customize the uri black list, by default tophold_rack will ignore uri begin with 'assets', 'uploads'.
44
+
45
+ Rails.configuration.tophold_rack_request_black_list << "admin"
46
+
47
+ The last thing is to specify which url to receive these parameters and to do the detaild parse job. I prefer node, it's bloody fast and non-block, will make the cost to the minimum level. Also you can push these parameters to a redis list, and parse it with blpop, it's up to you.
48
+
49
+ And the last, you can disable/enable this middleware by toggle the switch
50
+
51
+ Rails.configuration.tophold_rack_disabled = true/false
22
52
 
23
53
  ## Contributing
24
54
 
@@ -45,3 +45,7 @@ Rails.configuration.tophold_rack_request_black_list << "admin"
45
45
 
46
46
  #3rd party tracking url
47
47
  Rails.configuration.tophold_rack_tracking_url = "http://localhost:8888/tracking/"
48
+
49
+ #if Rails.env.development?
50
+ # Rails.configuration.tophold_rack_disabled = true
51
+ #end
@@ -7,6 +7,8 @@ module TopholdRack
7
7
  config.tophold_rack_request_black_list = ["uploads", "assets"]
8
8
 
9
9
  config.tophold_rack_tracking_url = "http://localhost:8888/tracking/"
10
+
11
+ config.tophold_rack_disabled = false
10
12
 
11
13
  initializer "tophold_rack.load_app_instance_data" do |app|
12
14
  TopholdRack.setup do |config|
@@ -14,15 +14,17 @@ module TopholdRack
14
14
  end
15
15
 
16
16
  def call env
17
- request = Rack::Request.new env
18
- if request.get?
19
- path, query = request.path, request.query_string
20
- scope = env["rack.session"]["warden.user.#{Rails.configuration.tophold_rack_devise_scope}.key"]
21
- user_id = scope ? scope[1][0] : nil
22
- unless path =~ request_black_list
23
- str = "#{path.blank? ? '/' : path}?query=#{query}&user_id=#{user_id}"
24
- url = Rails.configuration.tophold_rack_tracking_url+"?request_url=#{CGI.escape str}"
25
- open url
17
+ unless Rails.configuration.tophold_rack_disabled
18
+ request = Rack::Request.new env
19
+ if request.get?
20
+ path, query = request.path, request.query_string
21
+ scope = env["rack.session"]["warden.user.#{Rails.configuration.tophold_rack_devise_scope}.key"]
22
+ user_id = scope ? scope[1][0] : nil
23
+ unless path =~ request_black_list
24
+ str = "#{path.blank? ? '/' : path}?query=#{query}&user_id=#{user_id}"
25
+ url = Rails.configuration.tophold_rack_tracking_url+"?request_url=#{CGI.escape str}"
26
+ open url
27
+ end
26
28
  end
27
29
  end
28
30
  @app.call env #pass the buckets
@@ -1,3 +1,3 @@
1
1
  module TopholdRack
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.1"
3
3
  end
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.0.1
4
+ version: 0.1.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-03-22 00:00:00.000000000 Z
12
+ date: 2013-03-30 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