pusherable 1.2.3 → 1.3.0
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.
- checksums.yaml +4 -4
- data/.travis.yml +0 -1
- data/README.md +6 -0
- data/lib/pusherable.rb +34 -33
- data/lib/pusherable/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e81c50fffca963ff4a426b270f811ae3538da5c
|
4
|
+
data.tar.gz: df962dad85f7dbd422745164c5710f410a43b338
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab41203bc3440483075115863b094417a4c0045ae2fc882851d5f4111e5c7562c3a3d7c6584182c0c036da9929c8580939cc34ef88150f3da62aaaddc033d7aa
|
7
|
+
data.tar.gz: 6a2d12bcaf36130f6686e982645b4b3c1ac45bc1ac40d65c94fd16dfeebad1557c638c64b7469452bc881e60c73fde87fc61dc0b59cd9a70a9fb7ee05998477d
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -4,6 +4,10 @@
|
|
4
4
|
|
5
5
|
Adds callback hooks for your `ActiveModel` models for sending messages to a `Pusher` channel.
|
6
6
|
|
7
|
+
## Requirements
|
8
|
+
|
9
|
+
* Ruby 2.0+
|
10
|
+
|
7
11
|
## Installation
|
8
12
|
|
9
13
|
Install and configure `Pusher` to work on your application by following the [pusher gem's instructions](https://github.com/pusher/pusher-gem).
|
@@ -69,6 +73,8 @@ Currently this gem extends `ActiveRecord::Base` and `Mongoid::Document` (if defi
|
|
69
73
|
|
70
74
|
For any other `ActiveModel` compliant data store, simply mirror this statement.
|
71
75
|
|
76
|
+
This gem supports soft deletes when used with [paranoia](https://github.com/radar/paranoia).
|
77
|
+
|
72
78
|
## Contributing
|
73
79
|
|
74
80
|
1. Fork it
|
data/lib/pusherable.rb
CHANGED
@@ -10,55 +10,56 @@ module Pusherable
|
|
10
10
|
false
|
11
11
|
end
|
12
12
|
|
13
|
-
def pusherable(
|
13
|
+
def pusherable(channel="test_channel")
|
14
14
|
raise "Please `gem install pusher` and configure it to run in your app!" if Pusher.app_id.blank? || Pusher.key.blank? || Pusher.secret.blank?
|
15
15
|
|
16
|
-
class_attribute :
|
17
|
-
|
18
|
-
|
19
|
-
self.pusherable_channel = pusherable_channel
|
20
|
-
self.pusherable_triggers_active = true
|
16
|
+
class_attribute :pusherable_channel_obj
|
17
|
+
self.pusherable_channel_obj = channel
|
21
18
|
|
22
19
|
class << self
|
23
20
|
def pusherable_triggers?
|
24
|
-
|
21
|
+
Thread.current.thread_variable_get("#{self.name.underscore}_pusherable_triggers_active") != false
|
25
22
|
end
|
26
23
|
|
27
24
|
def activate_pusherable_triggers
|
28
|
-
self.
|
25
|
+
Thread.current.thread_variable_set "#{self.name.underscore}_pusherable_triggers_active", true
|
29
26
|
end
|
30
27
|
|
31
28
|
def deactivate_pusherable_triggers
|
32
|
-
self.
|
29
|
+
Thread.current.thread_variable_set "#{self.name.underscore}_pusherable_triggers_active", false
|
33
30
|
end
|
34
|
-
end
|
35
31
|
|
36
|
-
|
37
|
-
if defined?(Mongoid) && defined?(Mongoid::Document) && include?(Mongoid::Document)
|
38
|
-
after_create :pusherable_trigger_create, if: :pusherable_triggers_active
|
39
|
-
after_update :pusherable_trigger_update, if: :pusherable_triggers_active
|
40
|
-
before_destroy :pusherable_trigger_destroy, if: :pusherable_triggers_active
|
41
|
-
else
|
42
|
-
after_commit :pusherable_trigger_create, on: :create, if: :pusherable_triggers_active
|
43
|
-
after_commit :pusherable_trigger_update, on: :update, if: :pusherable_triggers_active
|
44
|
-
after_commit :pusherable_trigger_destroy, on: :destroy, if: :pusherable_triggers_active
|
45
|
-
end
|
46
|
-
|
47
|
-
def self.pusherable?
|
32
|
+
def pusherable?
|
48
33
|
true
|
49
34
|
end
|
50
35
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
if generated_pusherable_channel.arity > 0
|
56
|
-
generated_pusherable_channel.call(obj)
|
36
|
+
def pusherable_channel(obj=nil)
|
37
|
+
if pusherable_channel_obj.respond_to? :call
|
38
|
+
if pusherable_channel_obj.arity > 0
|
39
|
+
pusherable_channel_obj.call(obj)
|
57
40
|
else
|
58
|
-
|
41
|
+
pusherable_channel_obj.call
|
59
42
|
end
|
60
43
|
else
|
61
|
-
|
44
|
+
pusherable_channel_obj
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class_eval do
|
50
|
+
if defined?(Mongoid) && defined?(Mongoid::Document) && include?(Mongoid::Document)
|
51
|
+
after_create :pusherable_trigger_create, if: :pusherable_triggers?
|
52
|
+
after_update :pusherable_trigger_update, if: :pusherable_triggers?
|
53
|
+
before_destroy :pusherable_trigger_destroy, if: :pusherable_triggers?
|
54
|
+
else
|
55
|
+
after_commit :pusherable_trigger_create, on: :create, if: :pusherable_triggers?
|
56
|
+
|
57
|
+
if defined?(Paranoia) && include?(Paranoia)
|
58
|
+
after_update :pusherable_trigger_update, if: :pusherable_triggers?
|
59
|
+
before_destroy :pusherable_trigger_destroy, if: :pusherable_triggers?
|
60
|
+
else
|
61
|
+
after_commit :pusherable_trigger_update, on: :update, if: :pusherable_triggers?
|
62
|
+
after_commit :pusherable_trigger_destroy, on: :destroy, if: :pusherable_triggers?
|
62
63
|
end
|
63
64
|
end
|
64
65
|
|
@@ -79,15 +80,15 @@ module Pusherable
|
|
79
80
|
end
|
80
81
|
|
81
82
|
def pusherable_trigger_create
|
82
|
-
Pusher.
|
83
|
+
Pusher.trigger_async(pusherable_channel, "#{pusherable_class_name}.create", to_json)
|
83
84
|
end
|
84
85
|
|
85
86
|
def pusherable_trigger_update
|
86
|
-
Pusher.
|
87
|
+
Pusher.trigger_async(pusherable_channel, "#{pusherable_class_name}.update", to_json)
|
87
88
|
end
|
88
89
|
|
89
90
|
def pusherable_trigger_destroy
|
90
|
-
Pusher.
|
91
|
+
Pusher.trigger_async(pusherable_channel, "#{pusherable_class_name}.destroy", to_json)
|
91
92
|
end
|
92
93
|
end
|
93
94
|
end
|
data/lib/pusherable/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pusherable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony Coconate
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -165,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
165
|
version: '0'
|
166
166
|
requirements: []
|
167
167
|
rubyforge_project:
|
168
|
-
rubygems_version: 2.
|
168
|
+
rubygems_version: 2.4.5
|
169
169
|
signing_key:
|
170
170
|
specification_version: 4
|
171
171
|
summary: Adds callback hooks to your models for sending messages to a Pusher channel.
|