token_of_fire 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/token_of_fire/event_bus.rb +11 -6
- data/lib/token_of_fire/scope.rb +5 -1
- data/lib/token_of_fire/token.rb +9 -6
- data/lib/token_of_fire/version.rb +1 -1
- metadata +1 -2
- data/LICENSE.txt +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 680cac93df6254f8943a5ca40a1ebc549fbf5dd3
|
4
|
+
data.tar.gz: caf71d2806b520c6e79a795017952bd0d9457b92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa6ae31a7d631e2dae9f070e0f3770e7c4f301a98a320b13fb67013051c632eb2163b184666d627bbf8cb3f376a395fe473517701acf80cb9143eebd5c3d20b0
|
7
|
+
data.tar.gz: ce34dfdbbaa92516044b119b1fefad168283deb98de43a939c48bb7c6950992537dfadcfe66ba53f5d086f4be5aa43fddfcc0a05f0685403c95aeb698de9dd87
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'celluloid'
|
2
|
+
require 'forwardable'
|
2
3
|
|
3
4
|
module TokenOfFire
|
4
5
|
Event = Struct.new(:name, :scope, :payload)
|
@@ -7,15 +8,17 @@ module TokenOfFire
|
|
7
8
|
include Celluloid
|
8
9
|
exclusive :subscribe
|
9
10
|
|
11
|
+
extend Forwardable
|
12
|
+
def_delegators :@global_scope, :scope, :token, :unique_token
|
13
|
+
def_delegators :@global_token, :attach
|
14
|
+
|
10
15
|
def initialize
|
11
16
|
@subscriptions = TokenOfFire::Subscriptions.new
|
17
|
+
@global_scope = TokenOfFire::Scope.new(Celluloid::Actor.current)
|
18
|
+
@global_token = @global_scope.token
|
12
19
|
self
|
13
20
|
end
|
14
21
|
|
15
|
-
def scope(filter={})
|
16
|
-
TokenOfFire::Scope.new(Celluloid::Actor.current, filter, true)
|
17
|
-
end
|
18
|
-
|
19
22
|
def subscribe(event_name, scope, handler, handler_method)
|
20
23
|
uuid = @subscriptions.subscribe(event_name, scope, handler, handler_method)
|
21
24
|
# $stdout.puts "-- Subscribe event_name: #{event_name} #{uuid}"
|
@@ -52,11 +55,13 @@ module TokenOfFire
|
|
52
55
|
end
|
53
56
|
end
|
54
57
|
|
55
|
-
def fire(event_name,
|
58
|
+
def fire(event_name, payload, scope=nil)
|
59
|
+
scope ||= @global_scope.filter
|
56
60
|
perform(event_name, scope, payload, :async)
|
57
61
|
end
|
58
62
|
|
59
|
-
def fire_sync(event_name,
|
63
|
+
def fire_sync(event_name, payload, scope=nil)
|
64
|
+
scope ||= @global_scope.filter
|
60
65
|
perform(event_name, scope, payload, :sync)
|
61
66
|
end
|
62
67
|
|
data/lib/token_of_fire/scope.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module TokenOfFire
|
2
2
|
class Scope
|
3
|
-
def initialize(event_bus, filter={}
|
3
|
+
def initialize(event_bus, filter={})
|
4
4
|
@event_bus = event_bus
|
5
5
|
raise RuntimeError, "Provide hash please" unless filter.is_a? Hash
|
6
6
|
@filter = filter
|
@@ -22,6 +22,10 @@ module TokenOfFire
|
|
22
22
|
@subscriptions
|
23
23
|
end
|
24
24
|
|
25
|
+
def scope(filter={})
|
26
|
+
TokenOfFire::Scope.new(@event_bus, @filter.merge(filter))
|
27
|
+
end
|
28
|
+
|
25
29
|
def subscriptions
|
26
30
|
@subscriptions
|
27
31
|
end
|
data/lib/token_of_fire/token.rb
CHANGED
@@ -5,6 +5,7 @@ module TokenOfFire
|
|
5
5
|
@scope = scope
|
6
6
|
@uuid = SecureRandom.uuid
|
7
7
|
@unique = unique
|
8
|
+
@subscription_uuids = []
|
8
9
|
subscribe_to_all
|
9
10
|
end
|
10
11
|
|
@@ -15,11 +16,11 @@ module TokenOfFire
|
|
15
16
|
end
|
16
17
|
|
17
18
|
def fire(event_name, payload)
|
18
|
-
@event_bus.fire(event_name,
|
19
|
+
@event_bus.fire(event_name, payload, filter)
|
19
20
|
end
|
20
21
|
|
21
22
|
def fire_sync
|
22
|
-
@event_bus.fire_sync(event_name,
|
23
|
+
@event_bus.fire_sync(event_name, payload, filter)
|
23
24
|
end
|
24
25
|
|
25
26
|
def release
|
@@ -28,12 +29,14 @@ module TokenOfFire
|
|
28
29
|
end
|
29
30
|
end
|
30
31
|
|
32
|
+
def attach(event_name, handler, method_name)
|
33
|
+
@subscription_uuids << @event_bus.subscribe(event_name, filter, handler, method_name)
|
34
|
+
end
|
35
|
+
|
31
36
|
private
|
32
37
|
def subscribe_to_all
|
33
|
-
@
|
34
|
-
|
35
|
-
subscription[:event_name], filter, subscription[:handler], subscription[:method_name]
|
36
|
-
)
|
38
|
+
@scope.subscriptions.each do |subscription|
|
39
|
+
attach(subscription[:event_name], subscription[:handler], subscription[:method_name])
|
37
40
|
end
|
38
41
|
end
|
39
42
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: token_of_fire
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fernando Dario Alonso
|
@@ -62,7 +62,6 @@ files:
|
|
62
62
|
- .gitignore
|
63
63
|
- Gemfile
|
64
64
|
- LICENSE
|
65
|
-
- LICENSE.txt
|
66
65
|
- README.md
|
67
66
|
- Rakefile
|
68
67
|
- lib/token_of_fire.rb
|
data/LICENSE.txt
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2013 TODO: Write your name
|
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.
|