pluggaloid 1.5.0 → 1.6.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: cb97cc313e04d222f6f4513ce075cffb211337e5d4bda1f95b6be810d6faeee5
4
- data.tar.gz: af791c5310e60264c2e0ea17591bd9e5baf65e57a5c2c97e8d0ba282c751cf11
3
+ metadata.gz: 9a93383e1c1e927a50677dac1de618e66f2b558c9dd03ab0e1a4d8ca4d67a7c8
4
+ data.tar.gz: 226442cc3d33c6441ac51d705ac3b230fd53ba26de52e7b82cd82d0629a69bdc
5
5
  SHA512:
6
- metadata.gz: 36d56d8c824ec9e6f5486316aaf928bb9cd5a5a9966ec621150dac344cc8c3b9180e7ba51299aeb65b8332ce587e7ba9a82a963aa05024878247ef0000a40335
7
- data.tar.gz: 937450b9967accb7197a16b4a1815aa11ed7bd7e86d933302392d04b32c6e7e055978a5878d4974bd45e610929def0e66bfaf27c0c3c9255a96233a4f7f9eef4
6
+ metadata.gz: 04a64880fef38f6092ff1efb49b40f4eb84cc714b02605077663f3f9937453dec61de160aa727311f646a465aad79c0e3a15c6cd2dc935a2e6d33955d409b36c
7
+ data.tar.gz: 95d9e7309b800f3eee223336e00568e946e6d59eea3599db51c3b7c70fa380f8fca368611dd8622f32c6bc35309670f8f857e80a7bba5df6eb1d1c2f038a47df
data/.circleci/config.yml CHANGED
@@ -31,10 +31,13 @@ workflows:
31
31
  jobs:
32
32
  - build:
33
33
  name: 'ruby-2.5'
34
- ruby-version: '2.5.7'
34
+ ruby-version: '2.5.9'
35
35
  - build:
36
36
  name: 'ruby-2.6'
37
- ruby-version: '2.6.5'
37
+ ruby-version: '2.6.7'
38
38
  - build:
39
39
  name: 'ruby-2.7'
40
- ruby-version: '2.7.0'
40
+ ruby-version: '2.7.3'
41
+ - build:
42
+ name: 'ruby-3.0'
43
+ ruby-version: '3.0.1'
data/lib/pluggaloid.rb CHANGED
@@ -10,6 +10,7 @@ require 'pluggaloid/subscriber'
10
10
  require 'pluggaloid/filter'
11
11
  require 'pluggaloid/stream_generator'
12
12
  require "pluggaloid/handler_tag"
13
+ require 'pluggaloid/mirage'
13
14
  require 'pluggaloid/error'
14
15
 
15
16
  require 'delayer'
@@ -19,7 +19,8 @@ class Pluggaloid::Filter < Pluggaloid::Handler
19
19
  # [tags:] Pluggaloid::HandlerTag|Array フィルタのタグ
20
20
  # [&callback] コールバック
21
21
  def initialize(event, **kwrest, &callback)
22
- super
22
+ kwrest[:name] ||= '%s line %i' % callback.source_location
23
+ super(event, **kwrest)
23
24
  @callback = callback
24
25
  event.add_filter self end
25
26
 
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pluggaloid
4
+ module Mirage
5
+ MIRAGE_ID_BASE_NUMBER = 36
6
+
7
+ module Extend
8
+ # `Pluggaloid::Mirage` をincludeしたClassのうち、`pluggaloid_mirage_identity`
9
+ # メソッドを呼ばれたインスタンスを記録するオブジェクトを返す。
10
+ # 戻り値は、以下のメソッドに応答すること。
11
+ # - `repository#[](String id)` idに対応するオブジェクトを返す
12
+ # - `repository#[]=(String id, self obj)` objを記録する
13
+ # Class毎に適したコンテナを返すようにoverrideすること
14
+ def pluggaloid_mirage_repository
15
+ @pluggaloid_mirage_repository ||= {}
16
+ end
17
+ end
18
+
19
+ def self.unwrap(namespace:, id:)
20
+ klass = pluggaloid_mirage_classes[namespace]
21
+ if klass
22
+ result = klass.pluggaloid_mirage_repository[id]
23
+ unless result&.is_a?(Pluggaloid::Mirage) # nilの場合は常にraise
24
+ raise ArgumentError, "The id `#{id}' was not found."
25
+ end
26
+ result
27
+ else
28
+ raise ArgumentError, "The namespace `#{namespace}' was not found."
29
+ end
30
+ end
31
+
32
+ def self.included(klass)
33
+ klass.extend(Extend)
34
+ pluggaloid_mirage_classes[klass.to_s] = klass
35
+ end
36
+
37
+ def self.pluggaloid_mirage_classes
38
+ @pluggaloid_mirage_classes ||= {}
39
+ end
40
+
41
+ # このClassのなかで、Pluggaloid::Mirageがインスタンスを同定するためのid(String)を返す。
42
+ # このメソッドではなく、 `generate_pluggaloid_mirage_id` をoverrideすること
43
+ def pluggaloid_mirage_id
44
+ generate_pluggaloid_mirage_id.freeze.tap do |id|
45
+ self.class.pluggaloid_mirage_repository[id] = self
46
+ Mirage.pluggaloid_mirage_classes[self.class.to_s] ||= self.class
47
+ end
48
+ end
49
+
50
+ private
51
+
52
+ # このClassのなかで、Pluggaloid::Mirageがインスタンスを同定するためのid(String)を返す。
53
+ # Class毎に適したコンテナを返すようにoverrideすること
54
+ def generate_pluggaloid_mirage_id
55
+ object_id.to_s(MIRAGE_ID_BASE_NUMBER)
56
+ end
57
+ end
58
+ end
@@ -181,7 +181,7 @@ module Pluggaloid
181
181
  def collection(event_name, *specs, &block)
182
182
  event = vm.Event[event_name]
183
183
  mutation = Pluggaloid::Collection.new(event, *specs)
184
- add_event_filter(event_name) do |*args|
184
+ add_event_filter(event_name, name: 'collection(%s line %i)' % block.source_location) do |*args|
185
185
  if mutation.argument_hash_same?(args)
186
186
  mutation.values.each(&args[event.collect_index].method(:<<))
187
187
  end
@@ -1,3 +1,3 @@
1
1
  module Pluggaloid
2
- VERSION = '1.5.0'
2
+ VERSION = '1.6.0'
3
3
  end
@@ -0,0 +1,129 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/setup'
4
+ require 'minitest/autorun'
5
+
6
+ require 'pluggaloid'
7
+ require_relative 'helper'
8
+
9
+ describe(Pluggaloid::Plugin) do
10
+ include PluggaloidTestHelper
11
+
12
+ it 'resume' do
13
+ k = Class.new do
14
+ include Pluggaloid::Mirage
15
+ end
16
+ a = k.new
17
+ assert_equal(a, Pluggaloid::Mirage.unwrap(namespace: k.to_s, id: a.pluggaloid_mirage_id))
18
+ end
19
+
20
+ it 'custom mirage id' do
21
+ k = Class.new do
22
+ include Pluggaloid::Mirage
23
+
24
+ def initialize(a)
25
+ @a = a
26
+ end
27
+
28
+ def generate_pluggaloid_mirage_id
29
+ @a.to_s
30
+ end
31
+ end
32
+
33
+ a = k.new('same')
34
+ b = k.new('differ')
35
+ assert_equal('same', a.pluggaloid_mirage_id)
36
+ assert_equal(a, Pluggaloid::Mirage.unwrap(namespace: k.to_s, id: a.pluggaloid_mirage_id))
37
+ assert_equal('differ', b.pluggaloid_mirage_id)
38
+ assert_equal(b, Pluggaloid::Mirage.unwrap(namespace: k.to_s, id: b.pluggaloid_mirage_id))
39
+ end
40
+
41
+ it 'not confuse other mirage classese' do
42
+ definition = ->(*) do
43
+ include Pluggaloid::Mirage
44
+
45
+ def initialize(a)
46
+ @a = a
47
+ end
48
+
49
+ def generate_pluggaloid_mirage_id
50
+ @a.to_s
51
+ end
52
+ end
53
+
54
+ k = Class.new(&definition)
55
+ l = Class.new(&definition)
56
+
57
+ a = k.new('same')
58
+ b = l.new('same')
59
+ c = l.new('differ')
60
+
61
+ refute_equal(k.to_s, l.to_s)
62
+ assert_equal('same', a.pluggaloid_mirage_id)
63
+ assert_equal('same', b.pluggaloid_mirage_id)
64
+ assert_equal('differ', c.pluggaloid_mirage_id)
65
+
66
+ assert_equal(b, Pluggaloid::Mirage.unwrap(namespace: l.to_s, id: 'same'))
67
+ assert_equal(c, Pluggaloid::Mirage.unwrap(namespace: l.to_s, id: 'differ'))
68
+ assert_equal(a, Pluggaloid::Mirage.unwrap(namespace: k.to_s, id: 'same'))
69
+ assert_raises(Pluggaloid::ArgumentError) { Pluggaloid::Mirage.unwrap(namespace: k.to_s, id: 'differ') }
70
+ end
71
+
72
+ it 'inherit class' do
73
+ k = Class.new do
74
+ include Pluggaloid::Mirage
75
+
76
+ def initialize(a)
77
+ @a = a
78
+ end
79
+
80
+ def generate_pluggaloid_mirage_id
81
+ @a.to_s
82
+ end
83
+ end
84
+ l = Class.new(k)
85
+
86
+ a = k.new('same')
87
+ b = l.new('same')
88
+ c = l.new('differ')
89
+
90
+ refute_equal(k.to_s, l.to_s)
91
+ assert_equal('same', a.pluggaloid_mirage_id)
92
+ assert_equal('same', b.pluggaloid_mirage_id)
93
+ assert_equal('differ', c.pluggaloid_mirage_id)
94
+
95
+ assert_equal(b, Pluggaloid::Mirage.unwrap(namespace: l.to_s, id: 'same'))
96
+ assert_equal(c, Pluggaloid::Mirage.unwrap(namespace: l.to_s, id: 'differ'))
97
+ assert_equal(a, Pluggaloid::Mirage.unwrap(namespace: k.to_s, id: 'same'))
98
+ assert_raises(Pluggaloid::ArgumentError) { Pluggaloid::Mirage.unwrap(namespace: k.to_s, id: 'differ') }
99
+ end
100
+
101
+ it 'inherit before include mirage' do
102
+ k = Class.new do
103
+ def initialize(a)
104
+ @a = a
105
+ end
106
+
107
+ def generate_pluggaloid_mirage_id
108
+ @a.to_s
109
+ end
110
+ end
111
+ l = Class.new(k)
112
+ k.include Pluggaloid::Mirage
113
+
114
+ a = k.new('same')
115
+ b = l.new('same')
116
+ c = l.new('differ')
117
+
118
+ refute_equal(k.to_s, l.to_s)
119
+ assert_equal('same', a.pluggaloid_mirage_id)
120
+ assert_equal('same', b.pluggaloid_mirage_id)
121
+ assert_equal('differ', c.pluggaloid_mirage_id)
122
+
123
+ assert_equal(b, Pluggaloid::Mirage.unwrap(namespace: l.to_s, id: 'same'))
124
+ assert_equal(c, Pluggaloid::Mirage.unwrap(namespace: l.to_s, id: 'differ'))
125
+ assert_equal(a, Pluggaloid::Mirage.unwrap(namespace: k.to_s, id: 'same'))
126
+ assert_raises(Pluggaloid::ArgumentError) { Pluggaloid::Mirage.unwrap(namespace: k.to_s, id: 'differ') }
127
+ end
128
+
129
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pluggaloid
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toshiaki Asai
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-14 00:00:00.000000000 Z
11
+ date: 2021-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: delayer
@@ -114,6 +114,7 @@ files:
114
114
  - lib/pluggaloid/handler_tag.rb
115
115
  - lib/pluggaloid/identity.rb
116
116
  - lib/pluggaloid/listener.rb
117
+ - lib/pluggaloid/mirage.rb
117
118
  - lib/pluggaloid/plugin.rb
118
119
  - lib/pluggaloid/stream.rb
119
120
  - lib/pluggaloid/stream_generator.rb
@@ -125,6 +126,7 @@ files:
125
126
  - test/handle_in_generate_test.rb
126
127
  - test/handler_tag_test.rb
127
128
  - test/helper.rb
129
+ - test/mirage_test.rb
128
130
  - test/multi_vm_test.rb
129
131
  - test/plugin_test.rb
130
132
  - test/reactive_test.rb
@@ -132,7 +134,7 @@ homepage: https://rubygems.org/gems/pluggaloid
132
134
  licenses:
133
135
  - MIT
134
136
  metadata: {}
135
- post_install_message:
137
+ post_install_message:
136
138
  rdoc_options: []
137
139
  require_paths:
138
140
  - lib
@@ -147,8 +149,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
149
  - !ruby/object:Gem::Version
148
150
  version: '0'
149
151
  requirements: []
150
- rubygems_version: 3.1.2
151
- signing_key:
152
+ rubygems_version: 3.2.13
153
+ signing_key:
152
154
  specification_version: 4
153
155
  summary: Extensible plugin system
154
156
  test_files:
@@ -157,6 +159,7 @@ test_files:
157
159
  - test/handle_in_generate_test.rb
158
160
  - test/handler_tag_test.rb
159
161
  - test/helper.rb
162
+ - test/mirage_test.rb
160
163
  - test/multi_vm_test.rb
161
164
  - test/plugin_test.rb
162
165
  - test/reactive_test.rb