entity_events 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e0b7c68e15961317833572b8d7a89052a333e67f
4
- data.tar.gz: fbcaef6d049367c14133c3f32d9e56c1dea2c3d9
3
+ metadata.gz: 7512e622b41651a0f5112a1db6c5b71d4a573ef7
4
+ data.tar.gz: 7cae9396d99bbaa6eefef46f3a810cbffa1d45a0
5
5
  SHA512:
6
- metadata.gz: 02e6cad9a181fd97885079a3b77976ab8339ca9ea321ce5696668d770897f94de3a66cf84506a3def7cd1714adba0256f81785ecb5e921c22a441d9e38ab2b45
7
- data.tar.gz: 8c8be966b40416101de3042ee95744ab4ef8f57e9db62c8928cc68714004ca7847b5753fe665d57741e53ff91c6cdc0abede19be69276c143ddf0376f9622733
6
+ metadata.gz: 237211222c3139b495a64fd89f5805425945aa333137d1e50462657da288575041ea6b14f074dd416e093b6d677465080fa0f5961da05a5e37a74d65dff75caf
7
+ data.tar.gz: ac365f123d9f2a25a1840eac22cf1085879acf38df16e2e3c26294e9da1d327ffad5079d54d122e8204bb6836d3bca8b8579c7ccc57abde04b43806ef5f8b59a
data/README.rdoc CHANGED
@@ -25,7 +25,9 @@ Additionally, all the requests params are stored in that interaction, as well as
25
25
 
26
26
  BASIC IMPLEMENTATION
27
27
 
28
- 1. Add to gemfile then bundle install
28
+ Steps 1-3 will have your rails app recording the Controller and Action for every Request. If the request is from an authenticated user, that user will be recorded. If entity_events can determine the target object from the params then that will also be recorded (i.e. On FooController Foo with id of 3 would be identified through params[:foo_id] or params[:id], in that order).
29
+
30
+ 1. Add entity_events to your gemfile then run bundle install
29
31
 
30
32
  ===ruby
31
33
  gem 'entity_events'
@@ -49,7 +51,7 @@ gem 'entity_events'
49
51
  end
50
52
  ===
51
53
 
52
- 3. On application_controller.rbgit
54
+ 3. On application_controller.rb
53
55
 
54
56
  ===ruby
55
57
  before_filter :entity_events
@@ -63,5 +65,104 @@ gem 'entity_events'
63
65
 
64
66
  CUSTOMIZATION
65
67
 
66
- The bool auto_log in application_controller.entity_events should be set to true
67
- Under /app/events/ create
68
+ 4. Recording events on a specific entity, rather than every entity
69
+ Maybe you don't want to record every single request, and you only want to record events on objects that you explicitly say to record. Revise the above ApplicationController code as follows.
70
+
71
+ ===ruby
72
+ before_filter :entity_events
73
+
74
+ def entity_events
75
+ auto_log = false
76
+ EntityEvents.record(params, current_user, auto_log)
77
+ end
78
+ ===
79
+
80
+ Then, given that you want to record Foo events, you create a file at /app/events/foo_events.rb
81
+
82
+ ===ruby
83
+
84
+ class FooEvent < EntityEvents::EntityEvent
85
+ def should_record?
86
+ true
87
+ end
88
+ end
89
+
90
+ ===
91
+
92
+ 5. Recording specific events on specific entities, rather than every event
93
+ Let's say you care when a Foo is Created, but not when someone requests the new Foo form. Do the following
94
+
95
+ ===ruby
96
+
97
+ class FooEvent < EntityEvents::EntityEvent
98
+ def new?
99
+ false
100
+ end
101
+
102
+ def create?
103
+ true
104
+ end
105
+ end
106
+
107
+ ===
108
+
109
+ 6. Unconventional actors and targets
110
+ entity_events does a very basic job of getting the actor and target; it says the actor is the authenticated_user, and the target is object of type params[:controller] with an id of params[:<object>_id] or params[:id]
111
+
112
+ In this sample, users belong to a group and a Foo has many Bars. Because we care how many bars a group of users make on any given Foo, we want to record the actor as the Group and the target as the Foo. You can do that!
113
+
114
+ ===ruby
115
+
116
+ class BarEvent < EntityEvents::EntityEvent
117
+ def new_actor
118
+ current_user.group
119
+ end
120
+
121
+ def new_target
122
+ id = params[:foo_id]
123
+ Foo.find id
124
+ end
125
+ end
126
+
127
+ ===
128
+
129
+ 7. Indicator Flags
130
+ Lets say you are analyzing user behavior. There are two buttons to create a new Bar, and you want to see which button people people use more to get to the new Bar form. So long as you are recording the new Bar action, it is as simple as setting the params[:flag] on the button as follows
131
+
132
+ ===html
133
+ <a id="new_bar_a" href="<%= new_bar_path({flag: 'a'}) %>" />
134
+ <a id="new_bar_b" href="<%= new_bar_path({flag: 'b'}) %>" />
135
+ ===
136
+
137
+ Maybe you think params[:flag] is ugly though, or perhaps you are already using it for something else, then you will want to override flag in your EntityEvent file to record params[:xyz]. You could do this on each file, as in overriding it on foo_event.rb and bar_event.rb. But if you want to make it normalized throughout your app it would be far simpler to create a new base EntityEvent which FooEvent and BarEvent would inherit from
138
+
139
+ ===ruby
140
+ class CustomEntityEvent < EntityEvents::EntityEvent
141
+ def flag
142
+ params[:xyz]
143
+ end
144
+ end
145
+
146
+ class FooEvent < CustomEntityEvent
147
+ ##
148
+ #I inherit flag from CustomEntityEvent so I don't need to implement it myself in order to receive params[:xyz]
149
+ ##
150
+ end
151
+ ===
152
+
153
+ 8. Other overrides
154
+ If you really want you can override controller, action, flag, default_actor, and default_target on your CustomEntityEvent or on a entity by entity basis (i.e. just for Foo entity in the FooEvent class)
155
+
156
+ ===ruby
157
+ class CustomEntityEvent < EntityEvents::EntityEvent
158
+ def default_actor
159
+ current_user.group
160
+ end
161
+ end
162
+ ===
163
+
164
+
165
+
166
+ TESTS
167
+
168
+ coming soon...
@@ -1,3 +1,3 @@
1
1
  module EntityEvents
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/entity_events.rb CHANGED
@@ -24,7 +24,6 @@ module EntityEvents
24
24
  attr_reader :actor, :action ,:target, :params, :current_user, :target_is_user_defined, :actor_is_user_defined
25
25
 
26
26
  def initialize(params,current_user)
27
- @auto_log = auto_log
28
27
  @params = params
29
28
  @action = action
30
29
  @current_user = current_user
@@ -51,10 +50,10 @@ module EntityEvents
51
50
  Interaction.log({
52
51
  actor: actor,
53
52
  target: target,
54
- action: params[:action],
55
- controller: params[:controller],
53
+ action: action,
54
+ controller: controller,
56
55
  parameters: YAML::dump(params),
57
- flag: params[:flag]
56
+ flag: flag
58
57
  })
59
58
  end
60
59
 
@@ -62,24 +61,39 @@ module EntityEvents
62
61
  self.class.name
63
62
  end
64
63
 
65
- #OVERRIDE FROM HERE
66
-
67
- def should_record?
64
+ #if auto_log == false, then should_record? will dictate is the action is recorded
65
+ def should_record?
66
+ action_method = (@action.to_s+'?').to_sym
67
+ if respond_to?(action_method)
68
+ #if <action>? is defined follow that
69
+ send action_method
70
+ else
71
+ #else if actor or target is defined, assume we are to record
68
72
  actor_is_user_defined || target_is_user_defined
69
73
  end
70
-
71
- def action
72
- params[:action]
73
- end
74
+ end
74
75
 
75
- def default_actor
76
- current_user
77
- end
76
+ #You can override methods after this line, however it is not nessisary.
77
+ def controller
78
+ params[:controller]
79
+ end
78
80
 
79
- def default_target
80
- id = params["#{params[:controller].to_s.singularize}_id"] || params[:id]
81
- params[:controller].classify.constantize.find id if id
82
- end
81
+ def action
82
+ params[:action]
83
+ end
84
+
85
+ def flag
86
+ params[:flag]
87
+ end
88
+
89
+ def default_actor
90
+ current_user
91
+ end
92
+
93
+ def default_target
94
+ id = params["#{params[:controller].to_s.singularize}_id"] || params[:id]
95
+ params[:controller].classify.constantize.find id if id
96
+ end
83
97
 
84
98
  end
85
99
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: entity_events
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Dean
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: 3.2.19
19
+ version: '3.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: 3.2.19
26
+ version: '3.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: sqlite3
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -39,7 +39,8 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  description: In a nut shell, it records whenever one entity interacts with another
42
- entity
42
+ entity. It also has more advanced features to allow specific event recording as
43
+ well as ab testing
43
44
  email:
44
45
  - josh@chalkle.com
45
46
  executables: []