realm-core 0.7.0 → 0.7.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: 0f61dae355ea08d78da40bc227540ce47635d09ac0f8645d3f70e1e53201ff54
4
- data.tar.gz: 57bfe266b33d2f7744b87af84b14a2bd0d7a3c25c0bfc6b452457488067ad181
3
+ metadata.gz: b7384c47348b48ded26a37ce232e0ccb357a8a6e7e1f25667d614f9dc37a8af2
4
+ data.tar.gz: 0b4ae6a517da7377f458111447453423652b35166fadbb60df74337727d68068
5
5
  SHA512:
6
- metadata.gz: 3568eca1b26cd974a6d860e233cb50d4911e49bd7f61f4d6c43d865e78cbded0d48dd40e6331fa8d46ce3eb8906a7093c797ce340e16e33c4fad441085199c72
7
- data.tar.gz: cca39336c0d199d46254e15293439b9e81f401b8e4a586f68eb90658a5e027888f4bce1911dad21dbbd6fb2a6c4c68e4380d47935d1492c962e84a092496f8de
6
+ metadata.gz: 4aa7ec7d85ce6777b58d13f6bf3ff691e83901124951f7ebb38b60c2fbf929bf58b6daec23631f8308147be8614f7ed82edce045855620de9ba6b05abab424b0
7
+ data.tar.gz: ca2605753e57f0290a2b834f455389dfcc57a0ad51515b7fdc0b75c4daf2a166d32c9039aea45ce09a9995d3807beb0ac8ae97b38c2b9682658e6d28f0237cb1
data/lib/realm/error.rb CHANGED
@@ -59,6 +59,4 @@ module Realm
59
59
  @validation_result.errors(full: true).to_h
60
60
  end
61
61
  end
62
-
63
- class UniqueConstraintError < Error; end
64
62
  end
@@ -7,6 +7,7 @@ module Realm
7
7
  class EventFactory
8
8
  def initialize(events_module)
9
9
  @events_module = events_module
10
+ @event_class_map = collect_event_classes(events_module)
10
11
  end
11
12
 
12
13
  def create_event(event_type, correlate: nil, cause: nil, **attributes)
@@ -19,15 +20,25 @@ module Realm
19
20
  def event_class_for(event_type)
20
21
  return event_type if event_type.respond_to?(:new)
21
22
 
22
- class_name = "#{@events_module}::#{event_type.to_s.camelize}"
23
- klass = class_name.safe_constantize || "#{class_name}Event".safe_constantize
24
- return klass if klass
25
-
26
- raise EventClassMissing.new(event_type, @events_module)
23
+ @event_class_map.fetch(event_type.to_s) do
24
+ raise EventClassMissing.new(event_type, @events_module)
25
+ end
27
26
  end
28
27
 
29
28
  private
30
29
 
30
+ def collect_event_classes(root_module)
31
+ root_module_str = root_module.to_s
32
+ root_module.constants.each_with_object({}) do |const_sym, all|
33
+ const = root_module.const_get(const_sym)
34
+ if !(const < Event) && const.to_s.start_with?(root_module_str)
35
+ all.merge!(collect_event_classes(const))
36
+ elsif const < Event
37
+ all[const.type] = const
38
+ end
39
+ end
40
+ end
41
+
31
42
  def enhance_head(head, correlate:, cause:)
32
43
  head[:correlation_id] = correlate.head.correlation_id if correlate
33
44
  if cause.is_a?(Event)
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'active_support/core_ext/string'
4
- require 'realm/error'
4
+ require 'realm/persistence'
5
5
  require 'realm/mixins/context_injection'
6
6
  require 'realm/mixins/reactive'
7
7
  require 'realm/mixins/repository_helper'
@@ -40,7 +40,7 @@ module Realm
40
40
 
41
41
  def identifier(value = :undefined)
42
42
  if value == :undefined
43
- defined?(@identifier) ? @identifier : name.gsub(/(Domain|EventHandlers?)/, '').underscore.gsub(%r{/+}, '-')
43
+ defined?(@identifier) ? @identifier : name.gsub(/(Domain|(Event)?Handlers?)/, '').underscore.gsub(%r{/+}, '-')
44
44
  else
45
45
  @identifier = value
46
46
  end
@@ -84,7 +84,7 @@ module Realm
84
84
  def call(event)
85
85
  event_to_methods(event).each do |method_name|
86
86
  send(method_name, event)
87
- rescue Realm::UniqueConstraintError => e
87
+ rescue Realm::Persistence::Conflict => e
88
88
  context[:logger]&.warn(e.full_message)
89
89
  end
90
90
  end
@@ -31,7 +31,7 @@ module Realm
31
31
  end
32
32
 
33
33
  def trigger(identifier, attributes = {})
34
- namespace, event_type = identifier.to_s.include?('.') ? identifier.split('.') : [nil, identifier]
34
+ namespace, event_type = identifier.to_s.include?('/') ? identifier.split('/') : [nil, identifier]
35
35
  gateway_for(namespace).trigger(event_type, attributes)
36
36
  end
37
37
 
@@ -14,6 +14,7 @@ module Realm
14
14
  end
15
15
 
16
16
  def register(handler_class)
17
+ # TODO: validate event_types for existence of matching class
17
18
  handler_class.event_types.each do |event_type|
18
19
  add_listener(event_type, handler_class.bind_runtime(@runtime))
19
20
  end
@@ -17,7 +17,7 @@ module Realm
17
17
  end
18
18
 
19
19
  def add_listener(event_type, listener)
20
- (@listener_map[event_type] ||= []) << listener
20
+ (@listener_map[event_type.to_sym] ||= []) << listener
21
21
  end
22
22
 
23
23
  def trigger(event_type, attributes = {})
@@ -39,7 +39,7 @@ module Realm
39
39
  private
40
40
 
41
41
  def find_listeners(event_type)
42
- @listener_map.fetch_values(event_type, :any) { [] }.flatten
42
+ @listener_map.fetch_values(event_type.to_sym, :any) { [] }.flatten
43
43
  end
44
44
 
45
45
  def gateways
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: realm-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - developers@reevoo.com
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-21 00:00:00.000000000 Z
11
+ date: 2021-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport