core-event 0.0.0 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/core/event/callable.rb +27 -5
- data/lib/core/event/compiler.rb +1 -0
- data/lib/core/event/version.rb +1 -1
- data/lib/is/eventable.rb +9 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0d60d72742e912882a23542ac744eae69448cf94622ccdc3c7229241e0963a6
|
4
|
+
data.tar.gz: 25d56626e04b153524515122204fd2270dbec0bb7467c259ed66b26726ff6e1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68661f7866444ff3a0255dc96b837d6b7115ce478bf449890d840a461ea000673d7e7b919d78f2e681de79c031db4d6243ab0b6f01f0f5445570b46511aa31c0
|
7
|
+
data.tar.gz: 6911ce75330056d954ef30ceabf67bd93a6a4dfe82160f0c83a168fa11883c5f375a2e33afcfe1239be3d26d45553fe8a0e9e773eaeb6f31c3dcc1189192263b
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## [v0.1.0](https://github.com/metabahn/corerb/releases/tag/2021-10-24)
|
2
|
+
|
3
|
+
*released on 2021-10-24*
|
4
|
+
|
5
|
+
* `fix` [#87](https://github.com/metabahn/corerb/pull/87) Yield to performing even when no callbacks are defined ([bryanp](https://github.com/bryanp))
|
6
|
+
* `chg` [#79](https://github.com/metabahn/corerb/pull/79) Support halt/reject from callbacks ([bryanp](https://github.com/bryanp))
|
7
|
+
* `chg` [#78](https://github.com/metabahn/corerb/pull/78) Add recompile support to eventable objects ([bryanp](https://github.com/bryanp))
|
8
|
+
|
1
9
|
## [v0.0.0](https://github.com/metabahn/corerb/releases/tag/2021-07-15)
|
2
10
|
|
3
11
|
*released on 2021-07-15*
|
data/lib/core/event/callable.rb
CHANGED
@@ -21,9 +21,31 @@ module Core
|
|
21
21
|
@pipelines = {}
|
22
22
|
end
|
23
23
|
|
24
|
+
def initialize_copy(...)
|
25
|
+
@pipelines = @pipelines.each_pair.each_with_object({}) { |(event, pipelines), pipelines_hash|
|
26
|
+
pipelines_hash[event] = pipelines.each_pair.each_with_object({}) { |(type, pipeline), events_hash|
|
27
|
+
events_hash[type] = pipeline.clone
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
super
|
32
|
+
end
|
33
|
+
|
24
34
|
attr_reader :events
|
25
35
|
attr_reader :pipelines
|
26
36
|
|
37
|
+
# [public] Relocates to another object context.
|
38
|
+
#
|
39
|
+
def relocate(object)
|
40
|
+
@object = object
|
41
|
+
|
42
|
+
@pipelines.each_value do |pipelines_hash|
|
43
|
+
pipelines_hash.each_value do |pipeline|
|
44
|
+
pipeline.relocate(object)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
27
49
|
# [public] Registers one or more events by name.
|
28
50
|
#
|
29
51
|
def register(*events)
|
@@ -40,18 +62,18 @@ module Core
|
|
40
62
|
define_callback(:after, *after, method: method, context: context, &block)
|
41
63
|
end
|
42
64
|
|
43
|
-
private def define_callback(type, *
|
44
|
-
|
65
|
+
private def define_callback(type, *events, method: nil, context: nil, &block)
|
66
|
+
events.each do |event|
|
45
67
|
@mutex.synchronize do
|
46
|
-
|
68
|
+
event = event.to_sym
|
47
69
|
|
48
|
-
@pipelines[
|
70
|
+
@pipelines[event] ||= {
|
49
71
|
before: Core::Pipeline::Callable.new(@object),
|
50
72
|
during: Core::Pipeline::Callable.new(@object),
|
51
73
|
after: Core::Pipeline::Callable.new(@object)
|
52
74
|
}
|
53
75
|
|
54
|
-
@pipelines[
|
76
|
+
@pipelines[event][type].action(method, context: context, &block)
|
55
77
|
end
|
56
78
|
end
|
57
79
|
end
|
data/lib/core/event/compiler.rb
CHANGED
data/lib/core/event/version.rb
CHANGED
data/lib/is/eventable.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "is/extension"
|
4
|
+
require "is/pipeline"
|
4
5
|
require "is/stateful"
|
5
6
|
|
6
7
|
require_relative "../core/event/callable"
|
@@ -31,7 +32,7 @@ module Is
|
|
31
32
|
end
|
32
33
|
end
|
33
34
|
|
34
|
-
extends :implementation, dependencies: [Is::Stateful] do
|
35
|
+
extends :implementation, dependencies: [Is::Pipeline, Is::Stateful] do
|
35
36
|
# [public] Calls callbacks for the given event with the given arguments.
|
36
37
|
#
|
37
38
|
def performing(event, ...)
|
@@ -49,6 +50,13 @@ module Is
|
|
49
50
|
def finished(event, ...)
|
50
51
|
@events.finished(self, event, ...)
|
51
52
|
end
|
53
|
+
|
54
|
+
# [public] Defines a callback to be called during, before, and/or after the given events, isolated to the instance.
|
55
|
+
#
|
56
|
+
def callback(*during, before: [], after: [], method: nil, context: nil, &block)
|
57
|
+
events.relocate(singleton_class)
|
58
|
+
events.callback(*during, before: before, after: after, method: method, context: context, &block)
|
59
|
+
end
|
52
60
|
end
|
53
61
|
end
|
54
62
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: core-event
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Powell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: core-extension
|
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
98
|
- !ruby/object:Gem::Version
|
99
99
|
version: '0'
|
100
100
|
requirements: []
|
101
|
-
rubygems_version: 3.2.
|
101
|
+
rubygems_version: 3.2.22
|
102
102
|
signing_key:
|
103
103
|
specification_version: 4
|
104
104
|
summary: Adds events to Ruby objects.
|