pusherable 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.travis.yml +1 -0
- data/README.md +22 -21
- data/lib/pusherable/version.rb +1 -1
- data/lib/pusherable.rb +3 -3
- data/spec/pusherable_spec.rb +4 -1
- data/spec/spec_helper.rb +5 -0
- metadata +4 -4
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -2,13 +2,13 @@
|
|
2
2
|
|
3
3
|
[](https://travis-ci.org/tonycoco/pusherable)
|
4
4
|
|
5
|
-
Adds callback hooks for your
|
5
|
+
Adds callback hooks for your _ActiveRecord_ models for sending messages to a _Pusher_ channel.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
9
|
-
Install and configure
|
9
|
+
Install and configure _Pusher_ to work on your application by following the [pusher gem's instructions](https://github.com/pusher/pusher-gem).
|
10
10
|
|
11
|
-
Then, add this line to your application's
|
11
|
+
Then, add this line to your application's _Gemfile_:
|
12
12
|
|
13
13
|
gem 'pusherable'
|
14
14
|
|
@@ -22,32 +22,34 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
Add in the following lines to any
|
25
|
+
Add in the following lines to any _ActiveRecord_ model class:
|
26
26
|
|
27
|
-
pusherable(
|
27
|
+
pusherable('some_channel')
|
28
28
|
|
29
|
-
|
29
|
+
_Pusherable_ has a default channel of `test_channel`, just like the _Pusher_ example docs, that it will publish to.
|
30
30
|
|
31
|
-
|
31
|
+
On your subscribed client(s), events will be triggered by _Pusher_ reflecting your _ActiveRecord_ create/update/destroy actions.
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
33
|
+
Here is a list of the _ActiveRecord_ callbacks that trigger _Pusher_ events...
|
34
|
+
|
35
|
+
ActiveRecord Callback => Triggered Event
|
36
|
+
----------------------------------------
|
37
|
+
after_create => "model.create"
|
38
|
+
after_update => "model.update"
|
39
|
+
before_destroy => "model.destroy"
|
38
40
|
|
39
41
|
### Example
|
40
42
|
|
41
|
-
If you have an
|
42
|
-
It will also carry a payload of data containing
|
43
|
+
If you have an _ActiveRecord_ model called, _Post_, and you create a new record, _Pusher_ will receive an event called, "post.create".
|
44
|
+
It will also carry a payload of data containing a _JSON_ representation of the record (literally calling `to_json` on the record).
|
43
45
|
|
44
|
-
The following callbacks that trigger
|
46
|
+
The following callbacks that trigger _Pusher_ events in this _Post_ example will then be...
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
-
"post.
|
49
|
-
"post.
|
50
|
-
|
48
|
+
ActiveRecord Callback => Triggered Event
|
49
|
+
----------------------------------------
|
50
|
+
after_create => "post.create"
|
51
|
+
after_update => "post.update"
|
52
|
+
before_destroy => "post.destroy"
|
51
53
|
|
52
54
|
## Contributing
|
53
55
|
|
@@ -56,4 +58,3 @@ The following callbacks that trigger Pusher events in this __Post__ example will
|
|
56
58
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
57
59
|
4. Push to the branch (`git push origin my-new-feature`)
|
58
60
|
5. Create new Pull Request
|
59
|
-
st
|
data/lib/pusherable/version.rb
CHANGED
data/lib/pusherable.rb
CHANGED
@@ -27,15 +27,15 @@ module Pusherable
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def pusherable_trigger_create
|
30
|
-
Pusher.trigger(pusherable_channel, "#{pusherable_class_name}.create",
|
30
|
+
Pusher.trigger(pusherable_channel, "#{pusherable_class_name}.create", self.to_json)
|
31
31
|
end
|
32
32
|
|
33
33
|
def pusherable_trigger_update
|
34
|
-
Pusher.trigger(pusherable_channel, "#{pusherable_class_name}.update",
|
34
|
+
Pusher.trigger(pusherable_channel, "#{pusherable_class_name}.update", self.to_json)
|
35
35
|
end
|
36
36
|
|
37
37
|
def pusherable_trigger_destroy
|
38
|
-
Pusher.trigger(pusherable_channel, "#{pusherable_class_name}.destroy",
|
38
|
+
Pusher.trigger(pusherable_channel, "#{pusherable_class_name}.destroy", self.to_json)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
data/spec/pusherable_spec.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Pusherable do
|
4
|
+
before do
|
5
|
+
Pusher.stub(:trigger).and_return true
|
6
|
+
end
|
7
|
+
|
4
8
|
describe 'setup' do
|
5
9
|
it 'should make ActiveRecord models pusherable' do
|
6
10
|
NonPusherableModel.pusherable?.should == false
|
@@ -12,7 +16,6 @@ describe Pusherable do
|
|
12
16
|
before(:each) do
|
13
17
|
@pusherable_model = PusherableModel.new
|
14
18
|
@non_pusherable_model = NonPusherableModel.new
|
15
|
-
Pusher.stub(:trigger).and_return true
|
16
19
|
end
|
17
20
|
|
18
21
|
it 'should trigger after create' do
|
data/spec/spec_helper.rb
CHANGED
@@ -3,6 +3,11 @@ require 'bundler/setup'
|
|
3
3
|
require 'active_record'
|
4
4
|
require 'database_cleaner'
|
5
5
|
require 'pusher'
|
6
|
+
|
7
|
+
Pusher.app_id = '123456'
|
8
|
+
Pusher.secret = 'FAKE'
|
9
|
+
Pusher.key = 'FAKE'
|
10
|
+
|
6
11
|
require 'pusherable'
|
7
12
|
|
8
13
|
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
|
metadata
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
name: pusherable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.0.
|
5
|
+
version: 1.0.4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Tony Coconate
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-03-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -157,7 +157,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
157
157
|
- !ruby/object:Gem::Version
|
158
158
|
segments:
|
159
159
|
- 0
|
160
|
-
hash:
|
160
|
+
hash: 4238303825927332364
|
161
161
|
version: '0'
|
162
162
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
163
163
|
none: false
|
@@ -166,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
166
166
|
- !ruby/object:Gem::Version
|
167
167
|
segments:
|
168
168
|
- 0
|
169
|
-
hash:
|
169
|
+
hash: 4238303825927332364
|
170
170
|
version: '0'
|
171
171
|
requirements: []
|
172
172
|
rubyforge_project:
|