entity_events 0.0.3 → 0.0.4

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: 7512e622b41651a0f5112a1db6c5b71d4a573ef7
4
- data.tar.gz: 7cae9396d99bbaa6eefef46f3a810cbffa1d45a0
3
+ metadata.gz: 74bf8f564354a645b0673da60e33a8a288cd31b7
4
+ data.tar.gz: 4e63f848a9c4f5dc2a984a304d6b89fba05820ee
5
5
  SHA512:
6
- metadata.gz: 237211222c3139b495a64fd89f5805425945aa333137d1e50462657da288575041ea6b14f074dd416e093b6d677465080fa0f5961da05a5e37a74d65dff75caf
7
- data.tar.gz: ac365f123d9f2a25a1840eac22cf1085879acf38df16e2e3c26294e9da1d327ffad5079d54d122e8204bb6836d3bca8b8579c7ccc57abde04b43806ef5f8b59a
6
+ metadata.gz: d4947ea792ae66b6f6ea6c7cbfd63a7318c474b0a2c9e3017c3051642f75646b6d3cc4c7d0d1820b77ae7b5fde26f1194c406ae80ff76dfa493129719286a875
7
+ data.tar.gz: 083188057510a07e4f9073486a54809bc3c783efe336d0dd7150b579aa6f4f98071f4bdc60af7cd2a98df3e2099260256094842aa4532d447980e386c07df126
data/README.rdoc CHANGED
@@ -16,26 +16,25 @@ This is the first gem I've written so beware if might be a little gnarly and ple
16
16
 
17
17
 
18
18
  DESCRIPTION OF FUNCTIONS
19
+
19
20
  Whenever a request is made an Interaction record is written to the database. An Interaction describes an 'actor' making an 'action' on a 'target'. This is usually the current_user, the controller action which the request is routed to, and the target the object the request is related to.
20
21
 
21
22
  i.e. { actor: User, action: Views, target: Post }
22
23
 
23
- Additionally, all the requests params are stored in that interaction, as well as the controller and action names (for querying purposes), and also an option params[:flag] which I added so I could record which href a user used to get there
24
+ Additionally, all that request's params are stored in that interaction, as well as the controller and action names (for querying purposes), and also an option params[:flag] which I added so I could record which href a user used to get there.
24
25
 
25
26
 
26
27
  BASIC IMPLEMENTATION
27
28
 
28
29
  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
 
30
- 1. Add entity_events to your gemfile then run bundle install
31
31
 
32
- ===ruby
32
+ ===1. Add entity_events to your gemfile then run bundle install
33
33
  gem 'entity_events'
34
34
  ===
35
35
 
36
36
  2. create and run a new migration
37
37
 
38
- ===ruby
39
38
  class CreateInteraction < ActiveRecord::Migration
40
39
  def change
41
40
  create_table :interactions do |t|
@@ -52,8 +51,6 @@ gem 'entity_events'
52
51
  ===
53
52
 
54
53
  3. On application_controller.rb
55
-
56
- ===ruby
57
54
  before_filter :entity_events
58
55
 
59
56
  def entity_events
@@ -65,10 +62,9 @@ gem 'entity_events'
65
62
 
66
63
  CUSTOMIZATION
67
64
 
68
- 4. Recording events on a specific entity, rather than every entity
69
65
  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
66
 
71
- ===ruby
67
+ ===4. Recording events on a specific entity, rather than every entity
72
68
  before_filter :entity_events
73
69
 
74
70
  def entity_events
@@ -79,7 +75,7 @@ Maybe you don't want to record every single request, and you only want to record
79
75
 
80
76
  Then, given that you want to record Foo events, you create a file at /app/events/foo_events.rb
81
77
 
82
- ===ruby
78
+ ===
83
79
 
84
80
  class FooEvent < EntityEvents::EntityEvent
85
81
  def should_record?
@@ -89,10 +85,10 @@ end
89
85
 
90
86
  ===
91
87
 
92
- 5. Recording specific events on specific entities, rather than every event
88
+
93
89
  Let's say you care when a Foo is Created, but not when someone requests the new Foo form. Do the following
94
90
 
95
- ===ruby
91
+ ===5. Recording specific events on specific entities, rather than every event
96
92
 
97
93
  class FooEvent < EntityEvents::EntityEvent
98
94
  def new?
@@ -106,12 +102,12 @@ end
106
102
 
107
103
  ===
108
104
 
109
- 6. Unconventional actors and targets
105
+
110
106
  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
107
 
112
108
  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
109
 
114
- ===ruby
110
+ ===6. Unconventional actors and targets
115
111
 
116
112
  class BarEvent < EntityEvents::EntityEvent
117
113
  def new_actor
@@ -126,17 +122,16 @@ end
126
122
 
127
123
  ===
128
124
 
129
- 7. Indicator Flags
130
125
  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
126
 
132
- ===html
127
+ ===7. Indicators
133
128
  <a id="new_bar_a" href="<%= new_bar_path({flag: 'a'}) %>" />
134
129
  <a id="new_bar_b" href="<%= new_bar_path({flag: 'b'}) %>" />
135
130
  ===
136
131
 
137
132
  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
133
 
139
- ===ruby
134
+ ===
140
135
  class CustomEntityEvent < EntityEvents::EntityEvent
141
136
  def flag
142
137
  params[:xyz]
@@ -150,10 +145,9 @@ Maybe you think params[:flag] is ugly though, or perhaps you are already using i
150
145
  end
151
146
  ===
152
147
 
153
- 8. Other overrides
154
148
  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
149
 
156
- ===ruby
150
+ ===8. Other overrides
157
151
  class CustomEntityEvent < EntityEvents::EntityEvent
158
152
  def default_actor
159
153
  current_user.group
@@ -1,3 +1,3 @@
1
1
  module EntityEvents
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/entity_events.rb CHANGED
@@ -15,7 +15,7 @@ module EntityEvents
15
15
  class << self
16
16
  def record(params, current_user, auto_log = true)
17
17
  event_finder = EventFinder.find(params[:controller])
18
- entity_event = event_finder.new params, current_user, auto_log
18
+ entity_event = event_finder.new params, current_user
19
19
  entity_event.record if auto_log || entity_event.should_record?
20
20
  end
21
21
  end
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.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Dean