startback 0.12.1 → 0.12.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/startback/context.rb +7 -0
- data/lib/startback/event/agent.rb +13 -2
- data/lib/startback/event/engine.rb +1 -1
- data/lib/startback/event.rb +1 -0
- data/lib/startback/version.rb +1 -1
- data/spec/spec_helper.rb +20 -0
- data/spec/unit/context/test_dup.rb +3 -7
- data/spec/unit/context/test_fork.rb +38 -0
- data/spec/unit/context/test_h_factory.rb +0 -20
- data/spec/unit/test_event.rb +5 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f4770d1267ad944224e11f6c10ddaae3f2c3666860ef31c05ea3323282dda34
|
4
|
+
data.tar.gz: ec1a61367ab0947be2088dae981c6956359a26bc2517282a464e44e6449331b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19813029ac9f81b1aed96f69a8e6ddd45e509d87e5b3bd05859f0b9155c16c5a05035cf2a28ff7df2df28f467a368702fa83180c24a62caf498337c3dde6d7da
|
7
|
+
data.tar.gz: 57abc7390c595f5c024276ed07ccb3580312d2de76a6a622e0a3284afefb38244b000b26e9f005d4516de67f3afccdc4789988466ffbb220f106cce3514f83b4
|
data/lib/startback/context.rb
CHANGED
@@ -112,6 +112,13 @@ module Startback
|
|
112
112
|
to_h.to_json(*args, &bl)
|
113
113
|
end
|
114
114
|
|
115
|
+
def fork(h = nil)
|
116
|
+
dup.tap{|duped|
|
117
|
+
self.class.h_factor!(duped, h) if h
|
118
|
+
yield(duped) if block_given?
|
119
|
+
}
|
120
|
+
end
|
121
|
+
|
115
122
|
def dup
|
116
123
|
super.tap{|c|
|
117
124
|
c.send(:clean_factored!)
|
@@ -16,9 +16,12 @@ module Startback
|
|
16
16
|
|
17
17
|
def initialize(engine)
|
18
18
|
@engine = engine
|
19
|
+
@context = nil
|
19
20
|
install_listeners
|
20
21
|
end
|
21
22
|
attr_reader :engine
|
23
|
+
attr_accessor :context
|
24
|
+
protected :context=
|
22
25
|
|
23
26
|
protected
|
24
27
|
|
@@ -40,7 +43,7 @@ module Startback
|
|
40
43
|
def async(exchange, queue)
|
41
44
|
bus.async.listen(exchange, queue) do |event_data|
|
42
45
|
event = engine.factor_event(event_data)
|
43
|
-
|
46
|
+
with_context(event.context).call(event)
|
44
47
|
end
|
45
48
|
end
|
46
49
|
|
@@ -50,7 +53,7 @@ module Startback
|
|
50
53
|
def sync(exchange, queue)
|
51
54
|
bus.listen(exchange, queue) do |event_data|
|
52
55
|
event = engine.factor_event(event_data)
|
53
|
-
|
56
|
+
with_context(event.context).call(event)
|
54
57
|
end
|
55
58
|
end
|
56
59
|
|
@@ -68,6 +71,14 @@ module Startback
|
|
68
71
|
raise NotImplementedError
|
69
72
|
end
|
70
73
|
|
74
|
+
def with_context(context)
|
75
|
+
dup.tap{|a| a.send(:context=, context) }
|
76
|
+
end
|
77
|
+
|
78
|
+
def operation_world(op)
|
79
|
+
super(op).merge(context: ctx)
|
80
|
+
end
|
81
|
+
|
71
82
|
end # class Agent
|
72
83
|
end # class Event
|
73
84
|
end # module Starback
|
data/lib/startback/event.rb
CHANGED
data/lib/startback/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -11,6 +11,26 @@ RSpec.configure do |c|
|
|
11
11
|
c.include SpecHelpers
|
12
12
|
end
|
13
13
|
|
14
|
+
class SubContext < Startback::Context
|
15
|
+
attr_accessor :foo
|
16
|
+
h_factory do |c,h|
|
17
|
+
c.foo = h["foo"]
|
18
|
+
end
|
19
|
+
h_dump do |h|
|
20
|
+
h.merge!("foo" => foo)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class SubContext
|
25
|
+
attr_accessor :bar
|
26
|
+
h_factory do |c,h|
|
27
|
+
c.bar = h["bar"]
|
28
|
+
end
|
29
|
+
h_dump do |h|
|
30
|
+
h.merge!("bar" => bar)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
14
34
|
class User
|
15
35
|
class Changed < Startback::Event
|
16
36
|
end
|
@@ -3,12 +3,8 @@ require 'spec_helper'
|
|
3
3
|
module Startback
|
4
4
|
describe Context, "dup" do
|
5
5
|
|
6
|
-
class Subcontext < Context
|
7
|
-
attr_accessor :foo
|
8
|
-
end
|
9
|
-
|
10
6
|
let(:context) {
|
11
|
-
|
7
|
+
SubContext.new.tap{|s| s.foo = "bar" }
|
12
8
|
}
|
13
9
|
|
14
10
|
class ContextRelatedAbstraction
|
@@ -27,7 +23,7 @@ module Startback
|
|
27
23
|
expect(x).not_to be(context)
|
28
24
|
}
|
29
25
|
expect(seen).to be(got)
|
30
|
-
expect(got).to be_a(
|
26
|
+
expect(got).to be_a(SubContext)
|
31
27
|
expect(got).not_to be(context)
|
32
28
|
expect(got.foo).to eql("bar")
|
33
29
|
end
|
@@ -43,4 +39,4 @@ module Startback
|
|
43
39
|
end
|
44
40
|
|
45
41
|
end
|
46
|
-
end
|
42
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Startback
|
4
|
+
describe Context, "fork" do
|
5
|
+
|
6
|
+
it 'is a simple dup without args' do
|
7
|
+
context = SubContext.new
|
8
|
+
context.foo = ['hello']
|
9
|
+
|
10
|
+
forked = context.fork
|
11
|
+
puts "Forked: #{forked.inspect}"
|
12
|
+
expect(fork).not_to be(context)
|
13
|
+
expect(forked.foo).to eql(['hello'])
|
14
|
+
expect(forked.foo).to be(context.foo)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'yields the context if a block is provided' do
|
18
|
+
context = SubContext.new
|
19
|
+
|
20
|
+
seen = false
|
21
|
+
context.fork({ 'foo' => 'hello' }) do |forked|
|
22
|
+
expect(fork).not_to be(context)
|
23
|
+
expect(forked.foo).to eql('hello')
|
24
|
+
seen = true
|
25
|
+
end
|
26
|
+
expect(seen).to eql(true)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'uses the factory on the hash provided' do
|
30
|
+
context = SubContext.new
|
31
|
+
|
32
|
+
forked = context.fork({ 'foo' => 'hello' })
|
33
|
+
expect(fork).not_to be(context)
|
34
|
+
expect(forked.foo).to eql('hello')
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -7,26 +7,6 @@ module Startback
|
|
7
7
|
expect(Context.new.to_json).to eql("{}")
|
8
8
|
end
|
9
9
|
|
10
|
-
class SubContext < Context
|
11
|
-
attr_accessor :foo
|
12
|
-
h_factory do |c,h|
|
13
|
-
c.foo = h["foo"]
|
14
|
-
end
|
15
|
-
h_dump do |h|
|
16
|
-
h.merge!("foo" => foo)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
class SubContext
|
21
|
-
attr_accessor :bar
|
22
|
-
h_factory do |c,h|
|
23
|
-
c.bar = h["bar"]
|
24
|
-
end
|
25
|
-
h_dump do |h|
|
26
|
-
h.merge!("bar" => bar)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
10
|
it 'allows installing factories' do
|
31
11
|
expect(Context.h_factories).to be_empty
|
32
12
|
expect(SubContext.h_factories.size).to eql(2)
|
data/spec/unit/test_event.rb
CHANGED
@@ -50,8 +50,11 @@ module Startback
|
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'accepts an explicit context as second argument' do
|
53
|
-
|
54
|
-
|
53
|
+
c = SubContext.new.tap{|x| x.foo = 'hello' }
|
54
|
+
evt = Event.json(JSON_SRC, c)
|
55
|
+
expect(evt.context).not_to be(c)
|
56
|
+
expect(evt.context).to be_a(SubContext)
|
57
|
+
expect(evt.context.foo).to eql('hello')
|
55
58
|
end
|
56
59
|
end
|
57
60
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: startback
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.12.
|
4
|
+
version: 0.12.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bernard Lambeau
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-05-
|
11
|
+
date: 2022-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -436,6 +436,7 @@ files:
|
|
436
436
|
- spec/unit/caching/test_entity_cache.rb
|
437
437
|
- spec/unit/context/test_abstraction_factory.rb
|
438
438
|
- spec/unit/context/test_dup.rb
|
439
|
+
- spec/unit/context/test_fork.rb
|
439
440
|
- spec/unit/context/test_h_factory.rb
|
440
441
|
- spec/unit/context/test_middleware.rb
|
441
442
|
- spec/unit/event/bus/memory/test_async.rb
|