eventish 0.2.0 → 0.3.0
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 +4 -4
- data/README.md +1 -2
- data/lib/eventish/adapters/active_support.rb +15 -7
- data/lib/eventish/event_api.rb +1 -2
- data/lib/eventish/version.rb +1 -1
- data/lib/eventish.rb +4 -14
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 965405052bda0cb9903d4a447c91e5db89c8b98a868ded8428ee0399652680bd
|
4
|
+
data.tar.gz: 4608f89362bd42919071b404d428c8a44178d608a51ae0c0eb2aeb0b9a3d40ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78839ea7b019d89e6587692faa575e345c9b72eae8355833cb374a5b7906cedd97ebcc74e4e61db1ecf9ea3c4764f5de7eeacac0a79bd6448c080f341ef33db3
|
7
|
+
data.tar.gz: 9b88eb7b02e330c68449cb7e978c8b40c6bc0a19cab874bd082fbf897ef61a9ec67ad3d2be866b3936d0370f777f158d423a414d3f469a4656facdfb8d201cb1
|
data/README.md
CHANGED
@@ -88,8 +88,7 @@ module Main
|
|
88
88
|
|
89
89
|
class << self
|
90
90
|
def event_name
|
91
|
-
# this is optional, if not set the
|
92
|
-
# in this sample it would be "test" - TestEvent => underscore => remove _event suffix
|
91
|
+
# this is optional, if not set the class name to string will be used
|
93
92
|
'some_event'
|
94
93
|
end
|
95
94
|
end
|
@@ -4,19 +4,27 @@ module Eventish
|
|
4
4
|
class Adapters
|
5
5
|
class ActiveSupport
|
6
6
|
class << self
|
7
|
-
def publish(
|
8
|
-
|
7
|
+
def publish(event, target = nil, block: nil)
|
8
|
+
raise ArgumentError, 'Missing event to publish' if event.nil?
|
9
|
+
|
10
|
+
options = { block: block }
|
11
|
+
::ActiveSupport::Notifications.instrument(event.to_s, target: target, options: options)
|
9
12
|
end
|
10
13
|
|
11
|
-
def subscribe(
|
12
|
-
|
14
|
+
def subscribe(event, handler)
|
15
|
+
raise ArgumentError, 'Missing event to subscribe' if event.nil?
|
16
|
+
raise ArgumentError, 'Missing handler for subscription' if handler.nil?
|
17
|
+
|
18
|
+
::ActiveSupport::Notifications.subscribe(event.to_s) do |name, start, finish, id, payload|
|
13
19
|
args = { event: name, id: id, start: start, finish: finish }
|
14
|
-
handler.trigger(payload[:target], args, &payload
|
20
|
+
handler.trigger(payload[:target], args, &payload.dig(:options, :block))
|
15
21
|
end
|
16
22
|
end
|
17
23
|
|
18
|
-
def unsubscribe(
|
19
|
-
|
24
|
+
def unsubscribe(event)
|
25
|
+
raise ArgumentError, 'Missing event to unsubscribe' if event.nil?
|
26
|
+
|
27
|
+
::ActiveSupport::Notifications.unsubscribe(event.to_s)
|
20
28
|
end
|
21
29
|
end
|
22
30
|
end
|
data/lib/eventish/event_api.rb
CHANGED
data/lib/eventish/version.rb
CHANGED
data/lib/eventish.rb
CHANGED
@@ -6,7 +6,7 @@ require_relative 'eventish/simple_event'
|
|
6
6
|
module Eventish
|
7
7
|
OPTIONS = %i[adapter].freeze
|
8
8
|
|
9
|
-
|
9
|
+
AdapterError = Class.new(StandardError)
|
10
10
|
|
11
11
|
module_function
|
12
12
|
|
@@ -18,25 +18,15 @@ module Eventish
|
|
18
18
|
@options ||= Struct.new(*OPTIONS).new # rubocop:disable Naming/MemoizedInstanceVariableName
|
19
19
|
end
|
20
20
|
|
21
|
-
def publish(event_name, target = nil,
|
22
|
-
config.adapter&.publish(event_name, target,
|
21
|
+
def publish(event_name, target = nil, block: nil)
|
22
|
+
config.adapter&.publish(event_name, target, block: block)
|
23
23
|
end
|
24
24
|
|
25
25
|
def setup
|
26
26
|
@options ||= Struct.new(*OPTIONS).new
|
27
27
|
yield(@options) if block_given?
|
28
|
-
raise
|
28
|
+
raise AdapterError, 'Please specify an event adapter' unless @options.adapter
|
29
29
|
|
30
30
|
@options
|
31
31
|
end
|
32
|
-
|
33
|
-
def underscore(camel_cased_word)
|
34
|
-
return camel_cased_word.to_s unless /[A-Z-]|::/.match?(camel_cased_word)
|
35
|
-
|
36
|
-
word = camel_cased_word.to_s.gsub(/\A.*::/, '')
|
37
|
-
word.gsub!(/([A-Z]+)(?=[A-Z][a-z])|([a-z\d])(?=[A-Z])/) { ($1 || $2) << "_" }
|
38
|
-
word.tr!("-", "_")
|
39
|
-
word.downcase!
|
40
|
-
word
|
41
|
-
end
|
42
32
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eventish
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mattia Roccoberton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-05-
|
11
|
+
date: 2022-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A simple and composable event library
|
14
14
|
email: mat@blocknot.es
|