mediator-rb 0.1.0 → 0.1.1

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
  SHA256:
3
- metadata.gz: fcec518e118433d3ebec5e4a06cc866d7e36c5558511952ec91323d50a228940
4
- data.tar.gz: eb6b84d7c8d823b8e6a03591f862a0887dccf839e8af66204e33b91c985623bb
3
+ metadata.gz: e5d8253174b40e2f587c18e5ca41341366468d7a60c29d9f8f02eccc4dd40911
4
+ data.tar.gz: ce3779e1c27799685445997a34ecf2db9cfce8a4f4223c3ee25d9a74807ca52d
5
5
  SHA512:
6
- metadata.gz: ee6f5a43a69921f186b9a60c3ccb324b02af3e91a67b98d3d53e6c37e909b03bcbec0942d10e1653f1e0fc0772ebd7834f05fe56887fe63ef84d18d9497a1ced
7
- data.tar.gz: beaef57e236c9e37b4bd171629f6afa9129dd340e897b734728d6ebad5fed3b13515a477b0cbb007d923fadb66ba80bdfe834d41108022e2760195e36cf37dd5
6
+ metadata.gz: b815cf49e6aa431e090789a804a3ce66b0fb9236560c83f7e599503b4e0ce20eec2b724edd4153878e4539c2807003071a9a5283301d8d7f0c51f10e64096e47
7
+ data.tar.gz: 3bb3764fe14444551f833912c4b29d95c00ceee2ae359bdee17acbc070522557cae602c8cf6c530812c5c3c7f10e855783cff5f5df76c1427c60bd92442476f0
data/.rspec CHANGED
@@ -1,3 +1,3 @@
1
- --format documentation
1
+ --format progress
2
2
  --color
3
3
  --require spec_helper
data/Gemfile.lock CHANGED
@@ -1,11 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mediator-rb (0.1.0)
4
+ mediator-rb (0.1.1)
5
+ concurrent-ruby
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
8
9
  specs:
10
+ concurrent-ruby (1.2.2)
9
11
  diff-lcs (1.5.0)
10
12
  rake (13.0.6)
11
13
  rspec (3.12.0)
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mediator
4
- module Rb
5
- VERSION = "0.1.0"
6
- end
4
+ VERSION = "0.1.1"
7
5
  end
@@ -0,0 +1 @@
1
+ require "mediator"
data/lib/mediator.rb ADDED
@@ -0,0 +1,51 @@
1
+ require 'concurrent/map'
2
+
3
+ module Mediator
4
+ def self.init
5
+ Instance.new
6
+ end
7
+
8
+ class Instance
9
+ MultipleHandlers = Class.new(StandardError)
10
+ UnregisteredHandler = Class.new(StandardError)
11
+
12
+ def initialize
13
+ @handlers = Concurrent::Map.new
14
+ @listeners = Concurrent::Map.new { |h, k| h.compute_if_absent(k) { [] } }
15
+ end
16
+
17
+ def handle(klass, handler)
18
+ raise MultipleHandlers, "Multiple handlers not allowed for #{klass}" if handlers[klass]
19
+
20
+ handlers[klass] = handler
21
+ end
22
+
23
+ def subscribe(klass, handler)
24
+ listeners[klass] << handler
25
+ end
26
+
27
+ def accept(request)
28
+ handler!(request).then do |handler|
29
+ handler.call(request)
30
+ end
31
+ end
32
+
33
+ def publish(event)
34
+ listeners!(event).each do |listener|
35
+ listener.call(event)
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ attr_reader :handlers, :listeners
42
+
43
+ def listeners!(event)
44
+ listeners.fetch(event.class) { raise UnregisteredHandler, "Missing listener for #{event.class}" }
45
+ end
46
+
47
+ def handler!(request)
48
+ handlers.fetch(request.class) { raise UnregisteredHandler, "Missing handler for #{request.class}" }
49
+ end
50
+ end
51
+ end
data/mediator-rb.gemspec CHANGED
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "lib/mediator/rb/version"
3
+ require_relative "lib/mediator/version"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "mediator-rb"
7
- spec.version = Mediator::Rb::VERSION
7
+ spec.version = Mediator::VERSION
8
8
  spec.authors = ["Laertis Pappas"]
9
9
  spec.email = ["laertis.pappas@gmail.com"]
10
10
 
@@ -30,5 +30,6 @@ Gem::Specification.new do |spec|
30
30
  spec.executables = []
31
31
  spec.require_paths = ["lib"]
32
32
 
33
+ spec.add_dependency "concurrent-ruby"
33
34
  spec.add_development_dependency "rspec"
34
35
  end
File without changes
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mediator-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Laertis Pappas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-04 00:00:00.000000000 Z
11
+ date: 2023-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: concurrent-ruby
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rspec
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,10 +52,11 @@ files:
38
52
  - LICENSE.txt
39
53
  - README.md
40
54
  - Rakefile
41
- - lib/mediator/rb.rb
42
- - lib/mediator/rb/version.rb
55
+ - lib/mediator-rb.rb
56
+ - lib/mediator.rb
57
+ - lib/mediator/version.rb
43
58
  - mediator-rb.gemspec
44
- - sig/mediator/rb.rbs
59
+ - sig/mediator/.gitignore
45
60
  homepage: https://www.github.com/laertispappas/mediator-rb
46
61
  licenses:
47
62
  - MIT
data/lib/mediator/rb.rb DELETED
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "rb/version"
4
-
5
- module Mediator
6
- module Rb
7
- class Error < StandardError; end
8
- # Your code goes here...
9
- end
10
- end
data/sig/mediator/rb.rbs DELETED
@@ -1,6 +0,0 @@
1
- module Mediator
2
- module Rb
3
- VERSION: String
4
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
- end
6
- end