tpitale-mongolytics 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -39,11 +39,16 @@ Simple analytics tracking for Rails using the awesomest: MongoDB
39
39
  track_change_stats # tracks create, update, destroy
40
40
  track_stats_for :new, :edit, :show, :destroy # track any action mix, other actions
41
41
 
42
- If you want to track a custom session variable:
42
+ If you want to track a session variable:
43
43
 
44
44
  track_session_key :username # tracks session[:username] as a String
45
45
  track_session_key :user_id, Integer # tracks session[:user_id] as an Integer
46
46
 
47
+ If you want to track a params variable:
48
+
49
+ track_params_key :username # tracks params[:username] as a String
50
+ track_params_key :user_id, Integer # tracks params[:user_id] as an Integer
51
+
47
52
  Later, retrieve stats via (given UsersController is our controller):
48
53
 
49
54
  # by path, useful for getting per-id stats e.g., /users/1
@@ -52,12 +57,10 @@ Simple analytics tracking for Rails using the awesomest: MongoDB
52
57
  # by controller and action keys, useful if you want all views of users/show page
53
58
  Mongolytics.stats_for_keys :users, :show # using the controller and action
54
59
 
55
- # by controller/action and session key/value hash
56
- Mongolytics.stats_for_keys :users, :show, :user_id => 1 # note: session keys, not request params
57
-
58
60
  You can always query the Statistics:
59
61
 
60
- Mongolytics::Statistic.count({:user_id => 1})
62
+ Mongolytics::Statistic.count(:session => {:user_id => 1})
63
+ Mongolytics::Statistic.count(:param => {:user_id => 1})
61
64
 
62
65
  ## Motivation
63
66
 
@@ -0,0 +1,5 @@
1
+ module Mongolytics
2
+ class Param
3
+ include MongoMapper::EmbeddedDocument
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Mongolytics
2
+ class Session
3
+ include MongoMapper::EmbeddedDocument
4
+ end
5
+ end
@@ -6,18 +6,15 @@ module Mongolytics
6
6
  key :action, String, :required => true
7
7
  key :path, String
8
8
 
9
- BASE_KEYS = ["updated_at", "action", "_id", "controller", "path", "created_at"]
10
-
11
- def self.session_keys
12
- keys.map{|k,v| k} - BASE_KEYS
13
- end
9
+ many :sessions
10
+ many :params
14
11
 
15
12
  def self.stats_for_path(path)
16
13
  count({:path => path})
17
14
  end
18
15
 
19
- def self.stats_for_keys(controller, action, session_key_hash = {})
20
- count({:controller => controller.to_s, :action => action.to_s}.merge(session_key_hash))
16
+ def self.stats_for_keys(controller, action)
17
+ count({:controller => controller.to_s, :action => action.to_s})
21
18
  end
22
19
  end
23
20
  end
@@ -11,12 +11,7 @@ module Mongolytics
11
11
  :path => request.path
12
12
  }
13
13
 
14
- session_options = Statistic.session_keys.inject({}) do |hash, key|
15
- hash[key.to_sym] = session[key.to_sym] if session.has_key?(key.to_sym)
16
- hash
17
- end
18
-
19
- Statistic.create(options.merge(session_options))
14
+ Statistic.create(options.merge(:sessions => [session], :params => [params]))
20
15
  end
21
16
 
22
17
  module ClassMethods
@@ -37,7 +32,11 @@ module Mongolytics
37
32
  end
38
33
 
39
34
  def track_session_key(key, type = String)
40
- Statistic.key(key, type)
35
+ Session.key(key, type)
36
+ end
37
+
38
+ def track_params_key(key, type = String)
39
+ Param.key(key, type)
41
40
  end
42
41
  end
43
42
  end
@@ -2,7 +2,7 @@ module Mongolytics
2
2
  module Version
3
3
 
4
4
  MAJOR = 0
5
- MINOR = 1
5
+ MINOR = 2
6
6
  TINY = 0
7
7
 
8
8
  def self.to_s # :nodoc:
data/lib/mongolytics.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  $:.unshift File.dirname(__FILE__)
2
2
 
3
3
  require 'mongolytics/statistic'
4
+ require 'mongolytics/session'
5
+ require 'mongolytics/param'
4
6
  require 'mongolytics/tracker'
5
7
 
6
8
  module Mongolytics
@@ -8,7 +10,7 @@ module Mongolytics
8
10
  Statistic.stats_for_path(path)
9
11
  end
10
12
 
11
- def self.stats_for_keys(controller, action, session_key_hash = {})
12
- Statistic.stats_for_keys(controller, action, session_key_hash)
13
+ def self.stats_for_keys(controller, action)
14
+ Statistic.stats_for_keys(controller, action)
13
15
  end
14
16
  end
@@ -12,16 +12,6 @@ module Mongolytics
12
12
  Statistic.expects(:count).with({:controller => 'users', :action => 'show'}).returns(11211)
13
13
  Statistic.stats_for_keys(:users, :show).should == 11211
14
14
  end
15
-
16
- should "find count of stats for a given controller/action and session key hash" do
17
- Statistic.expects(:count).with({:controller => 'users', :action => 'show', :user_id => 1}).returns(13131)
18
- Statistic.stats_for_keys(:users, :show, :user_id => 1).should == 13131
19
- end
20
-
21
- should "know of any session keys" do
22
- Statistic.key(:extra_key, String)
23
- assert_equal ["extra_key"], Statistic.session_keys
24
- end
25
15
  end
26
16
  end
27
17
  end
@@ -27,38 +27,46 @@ module Mongolytics
27
27
  FauxController.track_change_stats
28
28
  end
29
29
 
30
- should "add a session key to Statistic" do
31
- Statistic.expects(:key).with(:username, String)
30
+ should "add a session key to Session" do
31
+ Session.expects(:key).with(:username, String)
32
32
  FauxController.track_session_key :username
33
33
  end
34
34
 
35
- should "allow override of class type for key added to Statistic" do
36
- Statistic.expects(:key).with(:user_id, Integer)
35
+ should "allow override of class type for a session key added to Session" do
36
+ Session.expects(:key).with(:user_id, Integer)
37
37
  FauxController.track_session_key :user_id, Integer
38
38
  end
39
+
40
+ should "add a params key to Session" do
41
+ Param.expects(:key).with(:username, String)
42
+ FauxController.track_params_key :username
43
+ end
44
+
45
+ should "allow override of class type for a params key added to Session" do
46
+ Param.expects(:key).with(:user_id, Integer)
47
+ FauxController.track_params_key :user_id, Integer
48
+ end
39
49
  end
40
50
 
41
51
  context "An instance of a Controller with Tracker mixed-in" do
42
52
  should "create a statistic with controller, action, and path" do
43
53
  controller = FauxController.new
44
54
 
45
- controller.stubs(:request).returns(stub(:path => '/users/1'))
46
- controller.stubs(:params).returns({:controller => 'faux', :action => 'show'})
47
- controller.stubs(:session).returns({})
48
-
49
- Statistic.expects(:create).with(:controller => 'faux', :action => 'show', :path => '/users/1').returns(true)
50
- assert controller.track_stat
51
- end
52
-
53
- should "create a statistic with controller, action, path, and user_id" do
54
- FauxController.track_session_key :user_id, Integer
55
- controller = FauxController.new
55
+ params = {:controller => 'faux', :action => 'show'}
56
+ session = {}
56
57
 
57
58
  controller.stubs(:request).returns(stub(:path => '/users/1'))
58
- controller.stubs(:params).returns({:controller => 'faux', :action => 'show'})
59
- controller.stubs(:session).returns({:user_id => 1})
59
+ controller.stubs(:params).returns(params)
60
+ controller.stubs(:session).returns(session)
61
+
62
+ Statistic.expects(:create).with({
63
+ :controller => 'faux',
64
+ :action => 'show',
65
+ :path => '/users/1',
66
+ :params => [params],
67
+ :sessions => [session]
68
+ }).returns(true)
60
69
 
61
- Statistic.expects(:create).with(:controller => 'faux', :action => 'show', :path => '/users/1', :user_id => 1).returns(true)
62
70
  assert controller.track_stat
63
71
  end
64
72
  end
@@ -8,13 +8,8 @@ class MongolyticsTest < Test::Unit::TestCase
8
8
  end
9
9
 
10
10
  should "delegate stats_for_keys to Statistic" do
11
- Mongolytics::Statistic.expects(:stats_for_keys).with(:users, :show, {})
11
+ Mongolytics::Statistic.expects(:stats_for_keys).with(:users, :show)
12
12
  Mongolytics.stats_for_keys(:users, :show)
13
13
  end
14
-
15
- should "delegate stats_for_keys with session options to Statistic" do
16
- Mongolytics::Statistic.expects(:stats_for_keys).with(:users, :show, :user_id => 1)
17
- Mongolytics.stats_for_keys(:users, :show, :user_id => 1)
18
- end
19
14
  end
20
15
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tpitale-mongolytics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Pitale
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-12 00:00:00 -07:00
12
+ date: 2009-08-29 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -34,6 +34,8 @@ files:
34
34
  - README.md
35
35
  - Rakefile
36
36
  - lib/mongolytics
37
+ - lib/mongolytics/param.rb
38
+ - lib/mongolytics/session.rb
37
39
  - lib/mongolytics/statistic.rb
38
40
  - lib/mongolytics/tracker.rb
39
41
  - lib/mongolytics/version.rb
@@ -46,7 +48,6 @@ files:
46
48
  - test/unit/mongolytics_test.rb
47
49
  has_rdoc: false
48
50
  homepage: http://t.pitale.com
49
- licenses:
50
51
  post_install_message:
51
52
  rdoc_options: []
52
53
 
@@ -67,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
68
  requirements: []
68
69
 
69
70
  rubyforge_project:
70
- rubygems_version: 1.3.5
71
+ rubygems_version: 1.2.0
71
72
  signing_key:
72
73
  specification_version: 3
73
74
  summary: Provide basic analytics tracking, server-side, using mongodb