pubsub-rails 1.4.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f4ee17935563a745f1760abb89405a702d28e3f0
4
+ data.tar.gz: f14ad9a3284d036d5abdd88ec8284d16b54ed6b2
5
+ SHA512:
6
+ metadata.gz: 62ea341551ca5cdd9355c33f76336dbb85fd35137d0915bb3553ac64d9f70cdc003a12c948abb96f9566e9b1d758a8af21a087df1434bb3bc1001cc0ae797177
7
+ data.tar.gz: 9c2bb1c9cd2d3e7a04e26276c2fbabb48831dbd40e4c5af29e81779c567508d22457c83d4371120b48b951c2cd17132dc052e126c50597043488ddf5af511b8d
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ *.gem
2
+ *.rbc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pubsub-rails.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Maciej Walusiak
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 rabsztok
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # Pubsub::Rails
2
+
3
+ PubSub.js in your Asset Pipeline.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'pubsub-rails'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install pubsub-rails
18
+
19
+ ## Usage
20
+
21
+ Add the necessary library to `app/assets/javascripts/application.js`:
22
+
23
+ ```js
24
+ //= require pubsub
25
+ ```
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it ( https://github.com/[my-github-username]/pubsub-rails/fork )
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,8 @@
1
+ require "pubsub/rails/version"
2
+
3
+ module Pubsub
4
+ module Rails
5
+ class Engine < ::Rails::Engine
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module Pubsub
2
+ module Rails
3
+ VERSION = "1.4.2"
4
+ end
5
+ end
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pubsub/rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pubsub-rails"
8
+ spec.version = Pubsub::Rails::VERSION
9
+ spec.authors = ["Maciej Walusiak"]
10
+ spec.email = ["rabsztok@gmail.com"]
11
+ spec.summary = "Gem wrapping PubSub.js javascript library"
12
+ spec.homepage = "https://github.com/Rabsztok/pubsub-rails"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.require_paths = ["lib"]
17
+
18
+ spec.add_dependency "railties", ">= 3.1"
19
+ spec.add_development_dependency "bundler", "~> 1.6"
20
+ spec.add_development_dependency "rake"
21
+ end
@@ -0,0 +1,240 @@
1
+ opyright (c) 2010,2011,2012,2013,2014 Morgan Roderick http://roderick.dk
2
+ License: MIT - http://mrgnrdrck.mit-license.org
3
+
4
+ https://github.com/mroderick/PubSubJS
5
+ */
6
+ /*jslint white:true, plusplus:true, stupid:true*/
7
+ /*global
8
+ setTimeout,
9
+ module,
10
+ exports,
11
+ define,
12
+ require,
13
+ window
14
+ */
15
+ (function(root, factory){
16
+ 'use strict';
17
+
18
+ // CommonJS
19
+ if (typeof exports === 'object' && module){
20
+ module.exports = factory();
21
+
22
+ // AMD
23
+ } else if (typeof define === 'function' && define.amd){
24
+ define(factory);
25
+ // Browser
26
+ } else {
27
+ root.PubSub = factory();
28
+ }
29
+ }( ( typeof window === 'object' && window ) || this, function(){
30
+
31
+ 'use strict';
32
+
33
+ var PubSub = {},
34
+ messages = {},
35
+ lastUid = -1;
36
+
37
+ function hasKeys(obj){
38
+ var key;
39
+
40
+ for (key in obj){
41
+ if ( obj.hasOwnProperty(key) ){
42
+ return true;
43
+ }
44
+ }
45
+ return false;
46
+ }
47
+
48
+ /**
49
+ * Returns a function that throws the passed exception, for use as argument for setTimeout
50
+ * @param { Object } ex An Error object
51
+ */
52
+ function throwException( ex ){
53
+ return function reThrowException(){
54
+ throw ex;
55
+ };
56
+ }
57
+
58
+ function callSubscriberWithDelayedExceptions( subscriber, message, data ){
59
+ try {
60
+ subscriber( message, data );
61
+ } catch( ex ){
62
+ setTimeout( throwException( ex ), 0);
63
+ }
64
+ }
65
+
66
+ function callSubscriberWithImmediateExceptions( subscriber, message, data ){
67
+ subscriber( message, data );
68
+ }
69
+
70
+ function deliverMessage( originalMessage, matchedMessage, data, immediateExceptions ){
71
+ var subscribers = messages[matchedMessage],
72
+ callSubscriber = immediateExceptions ? callSubscriberWithImmediateExceptions : callSubscriberWithDelayedExceptions,
73
+ s;
74
+
75
+ if ( !messages.hasOwnProperty( matchedMessage ) ) {
76
+ return;
77
+ }
78
+
79
+ for (s in subscribers){
80
+ if ( subscribers.hasOwnProperty(s)){
81
+ callSubscriber( subscribers[s], originalMessage, data );
82
+ }
83
+ }
84
+ }
85
+
86
+ function createDeliveryFunction( message, data, immediateExceptions ){
87
+ return function deliverNamespaced(){
88
+ var topic = String( message ),
89
+ position = topic.lastIndexOf( '.' );
90
+
91
+ // deliver the message as it is now
92
+ deliverMessage(message, message, data, immediateExceptions);
93
+
94
+ // trim the hierarchy and deliver message to each level
95
+ while( position !== -1 ){
96
+ topic = topic.substr( 0, position );
97
+ position = topic.lastIndexOf('.');
98
+ deliverMessage( message, topic, data );
99
+ }
100
+ };
101
+ }
102
+
103
+ function messageHasSubscribers( message ){
104
+ var topic = String( message ),
105
+ found = Boolean(messages.hasOwnProperty( topic ) && hasKeys(messages[topic])),
106
+ position = topic.lastIndexOf( '.' );
107
+
108
+ while ( !found && position !== -1 ){
109
+ topic = topic.substr( 0, position );
110
+ position = topic.lastIndexOf( '.' );
111
+ found = Boolean(messages.hasOwnProperty( topic ) && hasKeys(messages[topic]));
112
+ }
113
+
114
+ return found;
115
+ }
116
+
117
+ function publish( message, data, sync, immediateExceptions ){
118
+ var deliver = createDeliveryFunction( message, data, immediateExceptions ),
119
+ hasSubscribers = messageHasSubscribers( message );
120
+
121
+ if ( !hasSubscribers ){
122
+ return false;
123
+ }
124
+
125
+ if ( sync === true ){
126
+ deliver();
127
+ } else {
128
+ setTimeout( deliver, 0 );
129
+ }
130
+ return true;
131
+ }
132
+
133
+ /**
134
+ * PubSub.publish( message[, data] ) -> Boolean
135
+ * - message (String): The message to publish
136
+ * - data: The data to pass to subscribers
137
+ * Publishes the the message, passing the data to it's subscribers
138
+ **/
139
+ PubSub.publish = function( message, data ){
140
+ return publish( message, data, false, PubSub.immediateExceptions );
141
+ };
142
+
143
+ /**
144
+ * PubSub.publishSync( message[, data] ) -> Boolean
145
+ * - message (String): The message to publish
146
+ * - data: The data to pass to subscribers
147
+ * Publishes the the message synchronously, passing the data to it's subscribers
148
+ **/
149
+ PubSub.publishSync = function( message, data ){
150
+ return publish( message, data, true, PubSub.immediateExceptions );
151
+ };
152
+
153
+ /**
154
+ * PubSub.subscribe( message, func ) -> String
155
+ * - message (String): The message to subscribe to
156
+ * - func (Function): The function to call when a new message is published
157
+ * Subscribes the passed function to the passed message. Every returned token is unique and should be stored if
158
+ * you need to unsubscribe
159
+ **/
160
+ PubSub.subscribe = function( message, func ){
161
+ if ( typeof func !== 'function'){
162
+ return false;
163
+ }
164
+
165
+ // message is not registered yet
166
+ if ( !messages.hasOwnProperty( message ) ){
167
+ messages[message] = {};
168
+ }
169
+
170
+ // forcing token as String, to allow for future expansions without breaking usage
171
+ // and allow for easy use as key names for the 'messages' object
172
+ var token = 'uid_' + String(++lastUid);
173
+ messages[message][token] = func;
174
+
175
+ // return token for unsubscribing
176
+ return token;
177
+ };
178
+
179
+ /* Public: Clears all subscriptions
180
+ */
181
+ PubSub.clearAllSubscriptions = function clearSubscriptions(){
182
+ messages = {};
183
+ };
184
+
185
+ /* Public: removes subscriptions.
186
+ * When passed a token, removes a specific subscription.
187
+ * When passed a function, removes all subscriptions for that function
188
+ * When passed a topic, removes all subscriptions for that topic (hierarchy)
189
+ *
190
+ * value - A token, function or topic to unsubscribe.
191
+ *
192
+ * Examples
193
+ *
194
+ * // Example 1 - unsubscribing with a token
195
+ * var token = PubSub.subscribe('mytopic', myFunc);
196
+ * PubSub.unsubscribe(token);
197
+ *
198
+ * // Example 2 - unsubscribing with a function
199
+ * PubSub.unsubscribe(myFunc);
200
+ *
201
+ * // Example 3 - unsubscribing a topic
202
+ * PubSub.unsubscribe('mytopic');
203
+ */
204
+ PubSub.unsubscribe = function(value){
205
+ var isTopic = typeof value === 'string' && messages.hasOwnProperty(value),
206
+ isToken = !isTopic && typeof value === 'string',
207
+ isFunction = typeof value === 'function',
208
+ result = false,
209
+ m, message, t, token;
210
+
211
+ if (isTopic){
212
+ delete messages[value];
213
+ return;
214
+ }
215
+
216
+ for ( m in messages ){
217
+ if ( messages.hasOwnProperty( m ) ){
218
+ message = messages[m];
219
+
220
+ if ( isToken && message[value] ){
221
+ delete message[value];
222
+ result = value;
223
+ // tokens are unique, so we can just stop here
224
+ break;
225
+ } else if (isFunction) {
226
+ for ( t in message ){
227
+ if (message.hasOwnProperty(t) && message[t] === value){
228
+ delete message[t];
229
+ result = true;
230
+ }
231
+ }
232
+ }
233
+ }
234
+ }
235
+
236
+ return result;
237
+ };
238
+
239
+ return PubSub;
240
+ }));
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pubsub-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.4.2
5
+ platform: ruby
6
+ authors:
7
+ - Maciej Walusiak
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - rabsztok@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - lib/pubsub/rails.rb
69
+ - lib/pubsub/rails/version.rb
70
+ - pubsub-rails.gemspec
71
+ - vendor/assets/javascripts/pubsub.js
72
+ homepage: https://github.com/Rabsztok/pubsub-rails
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.2.2
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Gem wrapping PubSub.js javascript library
96
+ test_files: []
97
+ has_rdoc: