token_of_fire 0.0.1 → 0.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 04dee45d965496063c510a9d07689a2d006df740
4
- data.tar.gz: 954c1fd598d8393048c3642d80f46697f9d5b3fe
3
+ metadata.gz: 680cac93df6254f8943a5ca40a1ebc549fbf5dd3
4
+ data.tar.gz: caf71d2806b520c6e79a795017952bd0d9457b92
5
5
  SHA512:
6
- metadata.gz: d86ace5e9fe0dac9ff30e1656130e0abede6380a33a439474a850d65f00d3505a6853ce198ceafdd1d25ea5aad4d0c0c174fe3a6b6141542019bedc52f1dd2e5
7
- data.tar.gz: 66882e4779a1ec6d9b5554c8bd0bddb61bc269255a4fab15781726ccaf497011d96c96ec64aa8e724faa5839ab98dec96c3aef0f6390d488db8c2ebfeb934aa5
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, scope, payload)
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, scope, payload)
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
 
@@ -1,6 +1,6 @@
1
1
  module TokenOfFire
2
2
  class Scope
3
- def initialize(event_bus, filter={}, single)
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
@@ -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, filter, payload)
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, filter, payload)
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
- @subscription_uuids = @scope.subscriptions.collect do |subscription|
34
- @event_bus.subscribe(
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
@@ -1,3 +1,3 @@
1
1
  module TokenOfFire
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  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.1
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.