shouter 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e691c8ec76258396c97ae227875d55e77dbf8635
4
- data.tar.gz: 820d5e90db24d53f64d0c25799bad6e67f7882b3
3
+ metadata.gz: 862686691e817c5a4673b19b99d32c67972dc50b
4
+ data.tar.gz: ca15331f3a161e1fa990405430bcf9cbbac97a1e
5
5
  SHA512:
6
- metadata.gz: 42071e236df2752dab9146506f476b617f1ee74948247a1fc272c359c8b5e46e55998546a808beba4339545d907f0b87f6099dc3ec336a57e79eaf31d8fa7718
7
- data.tar.gz: 7dc791ab3bbffd37dcf122343e49e44d694fde4ecbf38491893d388281c9d6c4f7cfa5db6480da73e5d6cc901a3ac9f4df164debdca10ee6650267dca0140526
6
+ metadata.gz: 72ad83a1d5cb0b462281464213c0e58651b315cc582c21b022e1feb1c2e1084a9254f7d393bb04c504be182c43605ddd1f6d63f4342cc0e89fd996dd6336e6f1
7
+ data.tar.gz: 0506b4d5a87e8ae891de958e3d7ebadd8423e6e2461a41b31a49bafa3c09138b1b534b43d949d4a2a650893e22348532471f9a6d6f63890229518bbd9945a848
data/README.md CHANGED
@@ -60,6 +60,10 @@ A.publish(:my_scope, :on_change)
60
60
  A.publish(:my_scope, :on_change)
61
61
  => nil
62
62
 
63
+ ```
64
+ All the arguments are passed to the method as well:
65
+ ```ruby
66
+ A.publish(:my_scope, :on_change_with_arguments, 'argument_1', 'argument_2')
63
67
  ```
64
68
 
65
69
  You can also pass a block to the publish method, which will serve as a
@@ -7,17 +7,19 @@ module Shouter
7
7
  end
8
8
 
9
9
  class Listener
10
- attr_reader :object, :options
10
+ attr_reader :object, :options, :scope
11
11
 
12
12
  def initialize(object, options)
13
13
  raise Shouter::ScopeMissingError unless options[:scope]
14
14
 
15
15
  @object = object
16
16
  @options = options
17
+ @scope = options[:scope]
17
18
  end
18
19
 
19
- def notify(event, args, &block)
20
- return unless object.respond_to?(event)
20
+ def notify(scope, event, args, &block)
21
+ return unless notification_allowed?(event, scope)
22
+
21
23
  if fire_guard!
22
24
  object.public_send(event, *args)
23
25
  fire_hook!(callback || block)
@@ -26,12 +28,12 @@ module Shouter
26
28
  end
27
29
  end
28
30
 
29
- def for?(scope)
30
- options[:scope] == scope
31
- end
32
-
33
31
  private
34
32
 
33
+ def notification_allowed?(event, desired_scope)
34
+ object.respond_to?(event) && scope == desired_scope
35
+ end
36
+
35
37
  def fire_hook!(callback)
36
38
  Shouter::Hook.(callback)
37
39
  end
File without changes
File without changes
@@ -6,6 +6,7 @@ module Shouter
6
6
 
7
7
  # Implement a simple Singleton pattern
8
8
  private_class_method :new
9
+
9
10
  @@listeners = []
10
11
  @@mutex = Mutex.new
11
12
 
@@ -17,7 +18,10 @@ module Shouter
17
18
 
18
19
  def register(objects, options)
19
20
  mutex.synchronize do
20
- objects.each { |object| @@listeners << Shouter::Listener.new(object, options) }
21
+ objects.each do |object|
22
+ subscribed_objects = @@listeners.map(&:object)
23
+ @@listeners << Shouter::Listener.new(object, options) unless subscribed_objects.include?(object)
24
+ end
21
25
  end
22
26
  end
23
27
 
@@ -36,9 +40,7 @@ module Shouter
36
40
  def notify(scope, event, args, &block)
37
41
  return if listeners.empty?
38
42
 
39
- listeners.select { |listener| listener.for?(scope) }.each do |listener|
40
- listener.notify(event, args, &block)
41
- end
43
+ listeners.each { |listener| listener.notify(scope, event, args, &block) }
42
44
  end
43
45
 
44
46
  def listeners
@@ -1,3 +1,3 @@
1
1
  module Shouter
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shouter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Slaveykov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-06 00:00:00.000000000 Z
11
+ date: 2017-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -73,6 +73,8 @@ files:
73
73
  - lib/shouter/guard.rb
74
74
  - lib/shouter/hook.rb
75
75
  - lib/shouter/listener.rb
76
+ - lib/shouter/registry/async.rb
77
+ - lib/shouter/registry/sync.rb
76
78
  - lib/shouter/store.rb
77
79
  - lib/shouter/version.rb
78
80
  - shouter.gemspec
@@ -96,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
98
  version: '0'
97
99
  requirements: []
98
100
  rubyforge_project:
99
- rubygems_version: 2.6.8
101
+ rubygems_version: 2.6.13
100
102
  signing_key:
101
103
  specification_version: 4
102
104
  summary: Small publish/subscription based system in Ruby