protocolist 0.8.1.beta → 0.9.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +10 -10
- data/lib/generators/protocolist/install/USAGE +1 -1
- data/lib/generators/protocolist/install/install_generator.rb +3 -3
- data/lib/generators/protocolist/install/templates/migration.rb +4 -4
- data/lib/protocolist.rb +6 -6
- data/lib/protocolist/controller_additions.rb +3 -3
- data/lib/protocolist/model_additions.rb +2 -2
- data/lib/protocolist/version.rb +1 -1
- data/protocolist.gemspec +2 -2
- data/spec/protocolist/controller_additions_spec.rb +11 -11
- data/spec/protocolist/model_additions_spec.rb +20 -20
- data/spec/protocolist_spec.rb +11 -11
- metadata +14 -14
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#Protocolist [![Build Status](https://secure.travis-ci.org/welldan97/protocolist.png?branch=master)](http://travis-ci.org/welldan97/protocolist)
|
1
|
+
#Protocolist [![Build Status](https://secure.travis-ci.org/welldan97/protocolist.png?branch=master)](http://travis-ci.org/welldan97/protocolist) [![Dependency Status](https://gemnasium.com/welldan97/protocolist.png)](https://gemnasium.com/welldan97/protocolist)
|
2
2
|
|
3
3
|
Simple activity feeds solution for Rails applications. Gives a flexible way to build activity feeds infrastructure over it.
|
4
4
|
|
@@ -26,12 +26,12 @@ rake db:migrate
|
|
26
26
|
Getting started
|
27
27
|
---------------
|
28
28
|
|
29
|
-
Activity model has four attributes:
|
30
|
-
they did"),
|
29
|
+
Activity model has four attributes: actor("who did it"), activity_type("what
|
30
|
+
they did"), target("what they did it to") and data(additional information). Subject will be
|
31
31
|
set as current user by default.
|
32
32
|
|
33
33
|
Protocolist expects you to have `current_user` method in a
|
34
|
-
controller. See [
|
34
|
+
controller. See [Changing Defaults](https://github.com/welldan97/protocolist/wiki/Changing-Defaults) to change this behavior.
|
35
35
|
|
36
36
|
If creation isn't possible it will silently skip it.
|
37
37
|
|
@@ -45,8 +45,8 @@ fires :create
|
|
45
45
|
```
|
46
46
|
|
47
47
|
When "create" event will be triggered, it will automatically create
|
48
|
-
Activity with current user set as
|
49
|
-
`self` as
|
48
|
+
Activity with current user set as actor, `:create` as type,
|
49
|
+
`self` as target and empty data.
|
50
50
|
|
51
51
|
The more convenient usage:
|
52
52
|
|
@@ -72,11 +72,11 @@ The most flexible way is to use `fire` method:
|
|
72
72
|
```ruby
|
73
73
|
def destroy_projects
|
74
74
|
self.projects.destroy_all
|
75
|
-
fire :destroy_all, :
|
75
|
+
fire :destroy_all, :target => false, :data => {:company_id => company_id}
|
76
76
|
end
|
77
77
|
```
|
78
78
|
|
79
|
-
If you run without `:
|
79
|
+
If you run without `:target` option set, it will default to `self`.
|
80
80
|
|
81
81
|
Usage in controllers
|
82
82
|
--------------------
|
@@ -98,7 +98,7 @@ fires :download, :only => [:download_report, :download_file, :download_map],
|
|
98
98
|
```
|
99
99
|
|
100
100
|
The `fire` method can be used same way as in models, but also if type is not
|
101
|
-
set, it will be set as `action_name`, and
|
101
|
+
set, it will be set as `action_name`, and target will try to store `@model_instance`.
|
102
102
|
|
103
103
|
```ruby
|
104
104
|
def show
|
@@ -111,7 +111,7 @@ is the same as
|
|
111
111
|
```ruby
|
112
112
|
def show
|
113
113
|
@article = Article.find(params[:id])
|
114
|
-
fire :show, :
|
114
|
+
fire :show, :target => @article
|
115
115
|
end
|
116
116
|
```
|
117
117
|
|
@@ -1 +1 @@
|
|
1
|
-
Generates both the Activity class and the migration to create its table. The table will have
|
1
|
+
Generates both the Activity class and the migration to create its table. The table will have actor, target, type and data columns.
|
@@ -11,9 +11,9 @@ module Protocolist
|
|
11
11
|
migration_template "migration.rb", "db/migrate/create_activities"
|
12
12
|
invoke "active_record:model", ['Activity'], :migration => false
|
13
13
|
model_content = <<CONTENT
|
14
|
-
attr_accessible :activity_type, :
|
15
|
-
belongs_to :
|
16
|
-
belongs_to :
|
14
|
+
attr_accessible :activity_type, :target, :actor, :data
|
15
|
+
belongs_to :target, :polymorphic => true
|
16
|
+
belongs_to :actor, :polymorphic => true
|
17
17
|
serialize :data
|
18
18
|
CONTENT
|
19
19
|
inject_into_class('app/models/activity.rb', 'Activity', model_content) if File.exists?(File.join(destination_root, 'app/models/activity.rb'))
|
@@ -1,14 +1,14 @@
|
|
1
1
|
class CreateActivities < ActiveRecord::Migration
|
2
2
|
def change
|
3
3
|
create_table :activities do |t|
|
4
|
-
t.references :
|
5
|
-
t.references :
|
4
|
+
t.references :actor, :polymorphic => true
|
5
|
+
t.references :target, :polymorphic => true
|
6
6
|
t.string :activity_type
|
7
7
|
t.text :data
|
8
8
|
|
9
9
|
t.timestamps
|
10
10
|
end
|
11
|
-
add_index :activities, :
|
12
|
-
add_index :activities, :
|
11
|
+
add_index :activities, :actor_id
|
12
|
+
add_index :activities, :target_id
|
13
13
|
end
|
14
14
|
end
|
data/lib/protocolist.rb
CHANGED
@@ -7,16 +7,16 @@ require "protocolist/railtie" if defined? Rails
|
|
7
7
|
module Protocolist
|
8
8
|
|
9
9
|
def self.fire activity_type, options={}
|
10
|
-
options = {:
|
11
|
-
@activity_class.create options if options[:
|
10
|
+
options = {:actor => @actor, :activity_type => activity_type}.merge options
|
11
|
+
@activity_class.create options if options[:actor] && @activity_class
|
12
12
|
end
|
13
13
|
|
14
|
-
def self.
|
15
|
-
@
|
14
|
+
def self.actor
|
15
|
+
@actor
|
16
16
|
end
|
17
17
|
|
18
|
-
def self.
|
19
|
-
@
|
18
|
+
def self.actor= actor
|
19
|
+
@actor = actor
|
20
20
|
end
|
21
21
|
|
22
22
|
def self.activity_class
|
@@ -35,15 +35,15 @@ module Protocolist
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def fire activity_type=nil, options={}
|
38
|
-
options[:
|
39
|
-
options[:
|
38
|
+
options[:target] = instance_variable_get("@#{self.controller_name.singularize}") if options[:target] == nil
|
39
|
+
options[:target] = nil if options[:target] == false
|
40
40
|
activity_type ||= action_name.to_sym
|
41
41
|
|
42
42
|
Protocolist.fire activity_type, options
|
43
43
|
end
|
44
44
|
|
45
45
|
def initilize_protocolist
|
46
|
-
Protocolist.
|
46
|
+
Protocolist.actor = current_user
|
47
47
|
Protocolist.activity_class = Activity
|
48
48
|
end
|
49
49
|
end
|
@@ -32,8 +32,8 @@ module Protocolist
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def fire activity_type, options={}
|
35
|
-
options[:
|
36
|
-
options[:
|
35
|
+
options[:target] = self if options[:target] == nil
|
36
|
+
options[:target] = nil if options[:target] == false
|
37
37
|
|
38
38
|
Protocolist.fire activity_type, options
|
39
39
|
end
|
data/lib/protocolist/version.rb
CHANGED
data/protocolist.gemspec
CHANGED
@@ -19,8 +19,8 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
21
|
s.add_development_dependency 'rake'
|
22
|
-
s.add_development_dependency 'rspec', '~> 2.
|
23
|
-
s.add_development_dependency 'guard-rspec', '~> 0.
|
22
|
+
s.add_development_dependency 'rspec', '~> 2.9.0'
|
23
|
+
s.add_development_dependency 'guard-rspec', '~> 0.7.0'
|
24
24
|
s.add_development_dependency 'supermodel'
|
25
25
|
s.add_development_dependency 'railties', '~> 3.0'
|
26
26
|
end
|
@@ -15,7 +15,7 @@ class FirestartersController
|
|
15
15
|
|
16
16
|
include Protocolist::ControllerAdditions
|
17
17
|
def explicit_use
|
18
|
-
fire :gogogo, :
|
18
|
+
fire :gogogo, :target => User.new(:name => 'Lisa'), :data => '<3 <3 <3'
|
19
19
|
end
|
20
20
|
|
21
21
|
def implicit_use
|
@@ -39,21 +39,21 @@ describe Protocolist::ControllerAdditions do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
describe 'direct fire method call' do
|
42
|
-
it 'saves record with
|
42
|
+
it 'saves record with target and data when called explicitly' do
|
43
43
|
@controller.explicit_use
|
44
44
|
|
45
|
-
Activity.last.
|
45
|
+
Activity.last.actor.name.should == 'Bill'
|
46
46
|
Activity.last.activity_type.should == :gogogo
|
47
|
-
Activity.last.
|
47
|
+
Activity.last.target.name.should == 'Lisa'
|
48
48
|
Activity.last.data.should == '<3 <3 <3'
|
49
49
|
end
|
50
50
|
|
51
|
-
it 'saves record with
|
51
|
+
it 'saves record with target and data when called implicitly' do
|
52
52
|
@controller.implicit_use
|
53
53
|
|
54
|
-
Activity.last.
|
54
|
+
Activity.last.actor.name.should == 'Bill'
|
55
55
|
Activity.last.activity_type.should == :quick_and_dirty_action_stub
|
56
|
-
Activity.last.
|
56
|
+
Activity.last.target.name.should == 'Marge'
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
@@ -65,9 +65,9 @@ describe Protocolist::ControllerAdditions do
|
|
65
65
|
expect {
|
66
66
|
callback_proc.call(@controller)
|
67
67
|
}.to change{Activity.count}.by 1
|
68
|
-
Activity.last.
|
68
|
+
Activity.last.actor.name.should == 'Bill'
|
69
69
|
Activity.last.activity_type.should == :download
|
70
|
-
Activity.last.
|
70
|
+
Activity.last.target.should_not be
|
71
71
|
end
|
72
72
|
FirestartersController.send(:fires, :download)
|
73
73
|
end
|
@@ -81,10 +81,10 @@ describe Protocolist::ControllerAdditions do
|
|
81
81
|
callback_proc.call(@controller)
|
82
82
|
}.to change{Activity.count}.by 1
|
83
83
|
|
84
|
-
Activity.last.
|
84
|
+
Activity.last.actor.name.should == 'Bill'
|
85
85
|
Activity.last.activity_type.should == :download
|
86
86
|
Activity.last.data.should == 'les params'
|
87
|
-
Activity.last.
|
87
|
+
Activity.last.target.should_not be
|
88
88
|
end
|
89
89
|
|
90
90
|
FirestartersController.send(:fires, :download,
|
@@ -12,7 +12,7 @@ class Firestarter < SuperModel::Base
|
|
12
12
|
include Protocolist::ModelAdditions
|
13
13
|
|
14
14
|
def delete
|
15
|
-
fire :delete, :
|
15
|
+
fire :delete, :target => false
|
16
16
|
end
|
17
17
|
|
18
18
|
def myself
|
@@ -21,7 +21,7 @@ class Firestarter < SuperModel::Base
|
|
21
21
|
|
22
22
|
def love_letter_for_mary
|
23
23
|
user = User.create(:name => 'Mary')
|
24
|
-
fire :love_letter, :
|
24
|
+
fire :love_letter, :target => user, :data => '<3 <3 <3'
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -49,7 +49,7 @@ end
|
|
49
49
|
class ComplexFirestarter < SuperModel::Base
|
50
50
|
include Protocolist::ModelAdditions
|
51
51
|
|
52
|
-
fires :yohoho, :on =>[:create, :destroy], :
|
52
|
+
fires :yohoho, :on =>[:create, :destroy], :target => false, :data => :hi
|
53
53
|
|
54
54
|
def hi
|
55
55
|
'Hi!'
|
@@ -59,8 +59,8 @@ end
|
|
59
59
|
describe Protocolist::ModelAdditions do
|
60
60
|
before :each do
|
61
61
|
Activity.destroy_all
|
62
|
-
@
|
63
|
-
Protocolist.
|
62
|
+
@actor = User.new(:name => 'Bill')
|
63
|
+
Protocolist.actor = @actor
|
64
64
|
Protocolist.activity_class = Activity
|
65
65
|
end
|
66
66
|
|
@@ -69,32 +69,32 @@ describe Protocolist::ModelAdditions do
|
|
69
69
|
@firestarter = Firestarter.new
|
70
70
|
end
|
71
71
|
|
72
|
-
it 'saves record with
|
72
|
+
it 'saves record with target and data' do
|
73
73
|
expect {
|
74
74
|
@firestarter.love_letter_for_mary
|
75
75
|
}.to change{Activity.count}.by 1
|
76
|
-
Activity.last.
|
76
|
+
Activity.last.actor.name.should == 'Bill'
|
77
77
|
Activity.last.activity_type.should == :love_letter
|
78
|
-
Activity.last.
|
78
|
+
Activity.last.target.name.should == 'Mary'
|
79
79
|
Activity.last.data.should == '<3 <3 <3'
|
80
80
|
end
|
81
81
|
|
82
|
-
it 'saves record with self as
|
82
|
+
it 'saves record with self as target if target is not set' do
|
83
83
|
expect {
|
84
84
|
@firestarter.myself
|
85
85
|
}.to change{Activity.count}.by 1
|
86
|
-
Activity.last.
|
86
|
+
Activity.last.actor.name.should == 'Bill'
|
87
87
|
Activity.last.activity_type.should == :myself
|
88
|
-
Activity.last.
|
88
|
+
Activity.last.target.should == @firestarter
|
89
89
|
end
|
90
90
|
|
91
|
-
it 'saves record without
|
91
|
+
it 'saves record without target if target set to false' do
|
92
92
|
expect {
|
93
93
|
@firestarter.delete
|
94
94
|
}.to change{Activity.count}.by 1
|
95
|
-
Activity.last.
|
95
|
+
Activity.last.actor.name.should == 'Bill'
|
96
96
|
Activity.last.activity_type.should == :delete
|
97
|
-
Activity.last.
|
97
|
+
Activity.last.target.should be_false
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
@@ -103,9 +103,9 @@ describe Protocolist::ModelAdditions do
|
|
103
103
|
expect {
|
104
104
|
SimpleFirestarter.create(:name => 'Ted')
|
105
105
|
}.to change{Activity.count}.by 1
|
106
|
-
Activity.last.
|
106
|
+
Activity.last.actor.name.should == 'Bill'
|
107
107
|
Activity.last.activity_type.should == :create
|
108
|
-
Activity.last.
|
108
|
+
Activity.last.target.name.should == 'Ted'
|
109
109
|
end
|
110
110
|
|
111
111
|
it 'saves record when called with complex options' do
|
@@ -115,9 +115,9 @@ describe Protocolist::ModelAdditions do
|
|
115
115
|
expect {
|
116
116
|
ComplexFirestarter.create(:name => 'Ted')
|
117
117
|
}.to change{Activity.count}.by 1
|
118
|
-
Activity.last.
|
118
|
+
Activity.last.actor.name.should == 'Bill'
|
119
119
|
Activity.last.activity_type.should == :yohoho
|
120
|
-
Activity.last.
|
120
|
+
Activity.last.target.should_not be
|
121
121
|
Activity.last.data.should == 'Hi!'
|
122
122
|
|
123
123
|
#then destroy record
|
@@ -125,9 +125,9 @@ describe Protocolist::ModelAdditions do
|
|
125
125
|
expect {
|
126
126
|
ComplexFirestarter.last.destroy
|
127
127
|
}.to change{Activity.count}.by 1
|
128
|
-
Activity.last.
|
128
|
+
Activity.last.actor.name.should == 'Bill'
|
129
129
|
Activity.last.activity_type.should == :yohoho
|
130
|
-
Activity.last.
|
130
|
+
Activity.last.target.should_not be
|
131
131
|
Activity.last.data.should == 'Hi!'
|
132
132
|
end
|
133
133
|
|
data/spec/protocolist_spec.rb
CHANGED
@@ -11,13 +11,13 @@ end
|
|
11
11
|
describe Protocolist do
|
12
12
|
before :each do
|
13
13
|
Activity.destroy_all
|
14
|
-
@
|
15
|
-
Protocolist.
|
14
|
+
@actor = User.new(:name => 'Bill')
|
15
|
+
Protocolist.actor = @actor
|
16
16
|
Protocolist.activity_class = Activity
|
17
17
|
end
|
18
18
|
|
19
|
-
it 'should silently skip saving if
|
20
|
-
Protocolist.
|
19
|
+
it 'should silently skip saving if actor is falsy' do
|
20
|
+
Protocolist.actor = nil
|
21
21
|
expect {Protocolist.fire :alarm}.not_to change{Activity.count}
|
22
22
|
expect {Protocolist.fire :alarm}.not_to raise_error
|
23
23
|
end
|
@@ -31,24 +31,24 @@ describe Protocolist do
|
|
31
31
|
it 'should save a simple record' do
|
32
32
|
expect {Protocolist.fire :alarm}.to change{Activity.count}.by 1
|
33
33
|
|
34
|
-
Activity.last.
|
34
|
+
Activity.last.actor.should == @actor
|
35
35
|
Activity.last.activity_type.should == :alarm
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'should save a complex record' do
|
39
|
-
|
40
|
-
|
39
|
+
another_actor = User.new(:name => 'Bob')
|
40
|
+
target = User.new(:name => 'Mary')
|
41
41
|
|
42
42
|
expect {
|
43
43
|
Protocolist.fire :alarm,
|
44
|
-
:
|
45
|
-
:
|
44
|
+
:actor => another_actor,
|
45
|
+
:target => target,
|
46
46
|
:data => {:some_attr => :some_data}
|
47
47
|
}.to change{Activity.count}.by 1
|
48
48
|
|
49
|
-
Activity.last.
|
49
|
+
Activity.last.actor.name.should == 'Bob'
|
50
50
|
Activity.last.activity_type.should == :alarm
|
51
|
-
Activity.last.
|
51
|
+
Activity.last.target.name.should == 'Mary'
|
52
52
|
Activity.last.data[:some_attr].should == :some_data
|
53
53
|
end
|
54
54
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: protocolist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0.beta
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-07-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &75671410 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,32 +21,32 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *75671410
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &75671120 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 2.
|
32
|
+
version: 2.9.0
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *75671120
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: guard-rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &75670800 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version: 0.
|
43
|
+
version: 0.7.0
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *75670800
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: supermodel
|
49
|
-
requirement: &
|
49
|
+
requirement: &75670540 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *75670540
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: railties
|
60
|
-
requirement: &
|
60
|
+
requirement: &75670090 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '3.0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *75670090
|
69
69
|
description: ! 'Simple activity feeds solution for Rails applications. Gives a flexible
|
70
70
|
way to build activity feeds infrastructure over it. '
|
71
71
|
email:
|