low_event 0.7.0 → 0.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 795d5b01229eb54ebe8f4a6ed2b19567f6076d4fade5fe84f3d4fb52eca08a33
4
- data.tar.gz: 3763c499defe0d8bf63dbcdbfa5913bcf670acfe9e34992c38d43a2fc49aec07
3
+ metadata.gz: 4bab872cc67259d94e7b3041b857c97eebf605a98ef4d7ec8150183e355ec1c7
4
+ data.tar.gz: c8b168ef52bc18c0cddf69f92e35f8d5d52ed9c3d7a939987e88bf7c878a7faf
5
5
  SHA512:
6
- metadata.gz: 04e478f509ad364b1fb67c14674264905013024b37ac52f0e737e354981f424842879d67b06656ad68c03375f069fcfc84b2a782fe05d9704465bd649d0991aa
7
- data.tar.gz: cff5e78df4c69a0cc862c11b80b1a115fcd1b7d1d7819f09ce3269da0f1bd7b48cae9f0a13bf305149e786befa2fce9b34989365a927c26bb3bc4a192cb69649
6
+ metadata.gz: 3583d5c6da3494dc0f437b9b0aea7cb4eb17e52ede03a5cb88ae404e770939c65d231681ec48b2513f82a3e74711ca54ebdeebfb56b667a900eb166bc6490a18
7
+ data.tar.gz: afbcfea6a595fe2f97ca188bca772947fe441f85d0d061b17d7cd1e2b6be1ad9d9f97181a0d3af4e2a2dcc64eeb10e8904f7bb1e0a03a08eda32fa8bfa70f3e3
@@ -7,7 +7,7 @@ module Low
7
7
  class RequestEvent < Event
8
8
  attr_reader :request
9
9
 
10
- def initialize(request:, action: :handle)
10
+ def initialize(request:, action: :request)
11
11
  super(key: self.class, action:)
12
12
 
13
13
  @request = request
@@ -10,6 +10,8 @@ module Low
10
10
 
11
11
  # TODO: Type: "response: Protocol::HTTP::Response"
12
12
  def initialize(response: nil)
13
+ super(key: self.class, action: :respond)
14
+
13
15
  @response = response
14
16
  end
15
17
  end
@@ -8,7 +8,7 @@ module Low
8
8
  class << self
9
9
  def response(body:)
10
10
  headers = Protocol::HTTP::Headers.new(['content-type', 'text/html'])
11
- body = Protocol::HTTP::Body::Buffered.wrap(body)
11
+ body = Protocol::HTTP::Body::Buffered.wrap(body.strip)
12
12
 
13
13
  Protocol::HTTP::Response.new('http/1.1', 200, headers, body)
14
14
  end
@@ -6,30 +6,32 @@ require_relative 'definable'
6
6
  require_relative '../support/value_object'
7
7
 
8
8
  module Low
9
- # An event represents what is currently happening in your application.
9
+ # An event represents what is currently happening; the past, present and future.
10
10
  #
11
- # Events are mutable in most cases (except for RenderEvent). They are action-driven, representing inputs and outputs
12
- # that are currently happening in a linear pipeline-like flow. They are present-tense and one-to-many with one return value.
13
- # The result of the previous event is made available to the next event. [UNRELEASED]
11
+ # They are action-driven, representing inputs and outputs in a linear pipeline-like flow,
12
+ # which end up as children of the event... which is why events are mutable (except for RenderEvent).
13
+ # They are one-to-many with a return value.
14
14
  #
15
15
  # Integrations:
16
16
  # - Observers for observer pattern which we wrap in an event-centric API
17
- # - EventPool for a tree of events and their child events
18
- # - LowState for state machines to trigger multiple actions [UNLRELEASED]
17
+ # - EventPool for a tree of events and their child events (defined in this gem)
18
+ # - LowState for state machines to trigger multiple ordered actions [UNLRELEASED]
19
19
  class Event
20
20
  include LowType
21
21
  include Observers
22
22
  include Events::Definable
23
23
  include Support::ValueObject
24
24
 
25
- attr_reader :key, :action, :created_at
25
+ attr_reader :key, :action, :actions, :created_at
26
26
  attr_accessor :children
27
27
 
28
- # The subclass will provide the key, usually "self.class".
29
- def initialize(key:, action: nil, children: [])
28
+ # Subclass provides a key such as "self.class".
29
+ def initialize(key:, action: nil, actions: [], children: [])
30
30
  @key = key
31
31
  @action = action
32
+ @actions = actions
32
33
  @children = children
34
+
33
35
  @created_at = Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond)
34
36
  end
35
37
 
@@ -45,13 +47,23 @@ module Low
45
47
  key.take(event: self) { restore_level(event_tree:) }
46
48
  end
47
49
 
50
+ def branch
51
+ event_tree = Providers['low.event.pool'].current_event_tree(event: self)
52
+ event_tree.branch(event: self)
53
+ end
54
+
55
+ private
56
+
57
+ def restore_level(event_tree:)
58
+ event_tree.current_event = self if event_tree.respond_to?(:current_event)
59
+ end
60
+
48
61
  class << self
49
62
  def trigger(**kwargs) = new(**kwargs).trigger
50
63
  def take(**kwargs) = new(**kwargs).take
51
64
 
52
65
  def inherited(child)
53
66
  child.include LowType
54
-
55
67
  increase_count
56
68
  add_event(child)
57
69
  end
@@ -72,16 +84,5 @@ module Low
72
84
  events << event
73
85
  end
74
86
  end
75
-
76
- private
77
-
78
- def branch
79
- event_tree = Providers['low.event.pool'].current_event_tree(event: self)
80
- event_tree.branch(event: self)
81
- end
82
-
83
- def restore_level(event_tree:)
84
- event_tree.current_event = self if event_tree.respond_to?(:current_event)
85
- end
86
87
  end
87
88
  end
@@ -14,23 +14,23 @@ module Low
14
14
  BUFFER_SIZE = 100
15
15
 
16
16
  def initialize
17
- @pool = Support::PoolHash.new(BUFFER_SIZE)
17
+ @event_trees = Support::PoolHash.new(BUFFER_SIZE)
18
18
  @request_counts = Support::PoolHash.new(BUFFER_SIZE)
19
19
  end
20
20
 
21
21
  def current_event_tree(event:)
22
22
  request_id = request_id(event:)
23
23
 
24
- return @pool[request_id] if @pool[request_id]
24
+ return @event_trees[request_id] if @event_trees[request_id]
25
25
 
26
- event_tree = @pool.add(request_id, EventTree.new(request_id:))
26
+ event_tree = @event_trees.add(request_id, EventTree.new(request_id:))
27
27
  trigger action: :new_event_tree, event: event_tree
28
28
 
29
29
  event_tree
30
30
  end
31
31
 
32
32
  def event_trees
33
- @pool
33
+ @event_trees
34
34
  end
35
35
 
36
36
  private
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Low
4
- EVENT_VERSION = '0.7.0'
4
+ EVENT_VERSION = '0.8.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: low_event
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - maedi
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  - !ruby/object:Gem::Version
107
107
  version: '0'
108
108
  requirements: []
109
- rubygems_version: 4.0.10
109
+ rubygems_version: 4.0.6
110
110
  specification_version: 4
111
111
  summary: Observable events
112
112
  test_files: []