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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 00fa038523b55253f2fb2ae761156aba79b2245a0ca23d37f6e98ca680e72294
4
- data.tar.gz: b2d61f6257aadf52fd08ece4673f396331e24bd91c2937d1187259d21ebf1210
3
+ metadata.gz: b0d60d72742e912882a23542ac744eae69448cf94622ccdc3c7229241e0963a6
4
+ data.tar.gz: 25d56626e04b153524515122204fd2270dbec0bb7467c259ed66b26726ff6e1e
5
5
  SHA512:
6
- metadata.gz: e4fcc7c585006d0aa67efb84cf3c772bc8c8da75e0a4f2d0d0828e4d47e171221818b7732476d20c4912e3b18d8ede9d37d58f0b4201773b5e4544ef46443ce3
7
- data.tar.gz: 310d42b592ec23553fa8544dc0a7721b8985090ce863b36dcf291bce7b96593927a97f9394ff372143c27c6652723ef85efa877134e39d669365571c7dd2941b
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*
@@ -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, *defined_events, method: nil, context: nil, &block)
44
- defined_events.each do |defined_event|
65
+ private def define_callback(type, *events, method: nil, context: nil, &block)
66
+ events.each do |event|
45
67
  @mutex.synchronize do
46
- defined_event = defined_event.to_sym
68
+ event = event.to_sym
47
69
 
48
- @pipelines[defined_event] ||= {
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[defined_event][type].action(method, context: context, &block)
76
+ @pipelines[event][type].action(method, context: context, &block)
55
77
  end
56
78
  end
57
79
  end
@@ -60,6 +60,7 @@ module Core
60
60
  if compiled.empty?
61
61
  <<~CODE
62
62
  validate_event(event.to_sym)
63
+ yield if block_given?
63
64
  CODE
64
65
  else
65
66
  <<~CODE
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Core
4
4
  module Event
5
- VERSION = "0.0.0"
5
+ VERSION = "0.1.0"
6
6
 
7
7
  def self.version
8
8
  VERSION
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.0.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-07-15 00:00:00.000000000 Z
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.15
101
+ rubygems_version: 3.2.22
102
102
  signing_key:
103
103
  specification_version: 4
104
104
  summary: Adds events to Ruby objects.