symbiont-ruby 0.1.0 → 0.2.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 +4 -4
- data/.rubocop.yml +7 -1
- data/.travis.yml +3 -1
- data/CHANGELOG.md +15 -0
- data/README.md +56 -17
- data/Rakefile +27 -3
- data/lib/symbiont.rb +20 -0
- data/lib/symbiont/context.rb +14 -9
- data/lib/symbiont/executor.rb +89 -24
- data/lib/symbiont/private_trigger.rb +11 -2
- data/lib/symbiont/public_trigger.rb +12 -3
- data/lib/symbiont/trigger.rb +39 -36
- data/lib/symbiont/version.rb +5 -1
- data/logo/render_sample_1.JPG +0 -0
- data/logo/render_sample_2.JPG +0 -0
- data/logo/symbiont_logo_circle.ai +1348 -0
- data/logo/symbiont_logo_circle.eps +0 -0
- data/logo/symbiont_logo_circle.jpg +0 -0
- data/logo/symbiont_logo_circle.pdf +1419 -1
- data/logo/symbiont_logo_circle.png +0 -0
- data/logo/symbiont_logo_circle.psd +0 -0
- data/logo/symbiont_logo_circle.svg +116 -0
- data/logo/symbiont_logo_circle.tif +0 -0
- data/logo/symbiont_logo_circle_black.ai +2048 -6
- data/logo/symbiont_logo_circle_black.eps +0 -0
- data/logo/symbiont_logo_circle_black.jpg +0 -0
- data/logo/symbiont_logo_circle_black.pdf +2217 -9
- data/logo/symbiont_logo_circle_black.png +0 -0
- data/logo/symbiont_logo_circle_black.psd +0 -0
- data/logo/symbiont_logo_circle_black.svg +120 -0
- data/logo/symbiont_logo_circle_black.tif +0 -0
- data/logo/symbiont_logo_hexagon.ai +1994 -3
- data/logo/symbiont_logo_hexagon.eps +0 -0
- data/logo/symbiont_logo_hexagon.jpg +0 -0
- data/logo/symbiont_logo_hexagon.pdf +2221 -5
- data/logo/symbiont_logo_hexagon.png +0 -0
- data/logo/symbiont_logo_hexagon.psd +0 -0
- data/logo/symbiont_logo_hexagon.svg +115 -0
- data/logo/symbiont_logo_hexagon.tif +0 -0
- data/logo/symbiont_logo_hexagon_black.ai +2073 -3
- data/logo/symbiont_logo_hexagon_black.eps +0 -0
- data/logo/symbiont_logo_hexagon_black.jpg +0 -0
- data/logo/symbiont_logo_hexagon_black.pdf +2157 -4
- data/logo/symbiont_logo_hexagon_black.png +0 -0
- data/logo/symbiont_logo_hexagon_black.psd +0 -0
- data/logo/symbiont_logo_hexagon_black.svg +126 -0
- data/logo/symbiont_logo_hexagon_black.tif +0 -0
- data/symbiont-ruby.gemspec +10 -9
- metadata +50 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2df520b8812cc17063343dec89c82fd4ef94feb5
|
4
|
+
data.tar.gz: 3ef7f4309989802c211aa91f234547c69ecc654a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c752120deaf778e7cf356b79beec8f2b471de4c3356993bd476239c25c23e7e1dbb540c5c2e39c37627aa6958c0306f209a97176ec038bc07767e9f5d01a708
|
7
|
+
data.tar.gz: 03f7fb48f8b91acd2e37260c4b6cfde7e18b4c2125ab4c2f2db56577c281f33bb4fc77a325ede3edb4a1a3e312afa37f85c4a69fb204b1d89cd96e763853e7b3
|
data/.rubocop.yml
CHANGED
@@ -39,6 +39,9 @@ Style/Documentation:
|
|
39
39
|
Style/ClassAndModuleChildren:
|
40
40
|
Enabled: false
|
41
41
|
|
42
|
+
Style/IfUnlessModifier:
|
43
|
+
Enabled: false
|
44
|
+
|
42
45
|
Style/EmptyCaseCondition:
|
43
46
|
Enabled: false
|
44
47
|
|
@@ -54,6 +57,9 @@ Style/ParallelAssignment:
|
|
54
57
|
Style/CommentedKeyword:
|
55
58
|
Enabled: false
|
56
59
|
|
60
|
+
Lint/HandleExceptions:
|
61
|
+
Enabled: false
|
62
|
+
|
57
63
|
Layout/IndentArray:
|
58
64
|
Enabled: false
|
59
65
|
|
@@ -70,7 +76,7 @@ Naming/VariableNumber:
|
|
70
76
|
EnforcedStyle: snake_case
|
71
77
|
|
72
78
|
Metrics/LineLength:
|
73
|
-
Max:
|
79
|
+
Max: 120
|
74
80
|
|
75
81
|
Metrics/BlockLength:
|
76
82
|
Exclude:
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,20 @@
|
|
1
1
|
# Changelog
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## [0.2.0] 2018-04-22
|
5
|
+
### Added
|
6
|
+
- Logo ^_^ (special thanks to **Viktoria Karaulova**)
|
7
|
+
- Support for multiple inner contexts: you can pass an array of objects as a context argument
|
8
|
+
to `Symbiont::Executor`. Each object will be used as an inner context in order they are passed.
|
9
|
+
|
10
|
+
### Changed
|
11
|
+
- Method signature: context direction should be passed as a named attribute `context_direction:`.
|
12
|
+
|
13
|
+
Affected methods:
|
14
|
+
- `Symbiont::Executor.evaluate`
|
15
|
+
- `Symbiont::Executor.evaluate_private`
|
16
|
+
- `Symbiont::Executor.public_method`
|
17
|
+
- `Symbiont::Executor.private_method`
|
18
|
+
|
4
19
|
## [0.1.0] - 2018-04-08
|
5
20
|
- Release :)
|
data/README.md
CHANGED
@@ -1,4 +1,12 @@
|
|
1
|
-
|
1
|
+
<p align="center"><img width="250" height="250" src="logo/symbiont_logo_circle.png" /></div>
|
2
|
+
<p align="center">
|
3
|
+
<h1 align="center">
|
4
|
+
Symbiont<br />
|
5
|
+
<a href="https://badge.fury.io/rb/symbiont-ruby"><img src="https://badge.fury.io/rb/symbiont-ruby.svg"></a>
|
6
|
+
<a href="https://travis-ci.org/0exp/symbiont-ruby"><img src="https://travis-ci.org/0exp/symbiont-ruby.svg?branch=master"></a>
|
7
|
+
<a href="https://coveralls.io/github/0exp/symbiont-ruby?branch=master"><img src="https://coveralls.io/repos/github/0exp/symbiont-ruby/badge.svg?branch=master"></a>
|
8
|
+
</h1>
|
9
|
+
</p>
|
2
10
|
|
3
11
|
**Symbiont** is a cool implementation of proc-objects execution algorithm: in the context of other object,
|
4
12
|
but with the preservation of the closed environment of the proc object and with the ability of control the method dispatch
|
@@ -46,6 +54,7 @@ require 'symbiont'
|
|
46
54
|
- [Symbiont Mixin](#symbiont-mixin)
|
47
55
|
- [Mixing a module with default delegation direction](#mixing-a-module-with-default-delegation-direction)
|
48
56
|
- [Mixing a module with certain delegation direction](#mixing-a-module-with-certain-delegation-direction)
|
57
|
+
- [Multiple inner contexts](#multiple-inner-contexts)
|
49
58
|
|
50
59
|
# Problems and motivaiton
|
51
60
|
|
@@ -193,15 +202,15 @@ Symbiont::KIO # Kernel Context => Inner Context => Outer Context
|
|
193
202
|
`Symbiont::Executor` allows you to execute proc objects in two modes of the delegation:
|
194
203
|
|
195
204
|
- only public methods:
|
196
|
-
- `evaluate(
|
205
|
+
- `evaluate(*required_contexts, [context_direction:], &closure)`
|
197
206
|
- public and private methods:
|
198
|
-
- `evaluate_private(
|
207
|
+
- `evaluate_private(*required_contexts, [context_direction:], &closure)`
|
199
208
|
|
200
209
|
If no context is able to respond to the required method - `Symbiont::Trigger::ContextNoMethodError` exception is thrown.
|
201
210
|
|
202
211
|
In the case when an unsupported direction value is used - `Symbiont::Trigger::IncompatibleContextDirectionError` exception is thrown.
|
203
212
|
|
204
|
-
If proc object isnt passed to the executor - `Symbiont::Trigger::
|
213
|
+
If proc object isnt passed to the executor - `Symbiont::Trigger::UnprovidedClosureAttributeError` exception is thrown.
|
205
214
|
|
206
215
|
#### Considering public methods only (.evaluate)
|
207
216
|
|
@@ -213,13 +222,13 @@ end
|
|
213
222
|
# => "Data: inner_context"
|
214
223
|
|
215
224
|
# with a custom delegation order
|
216
|
-
Symbiont::Executor.evaluate(object, Symbiont::KIO) do
|
225
|
+
Symbiont::Executor.evaluate(object, context_direction: Symbiont::KIO) do
|
217
226
|
format_data(object_data)
|
218
227
|
end
|
219
228
|
# => "Data: kernel_context"
|
220
229
|
|
221
230
|
# SimpleObject#object_data is a private method (inner_context)
|
222
|
-
Symbiont::Executor.evaluate(object, Symbiont::IOK) do
|
231
|
+
Symbiont::Executor.evaluate(object, context_direction: Symbiont::IOK) do
|
223
232
|
format_data(object_data)
|
224
233
|
end
|
225
234
|
# => "Data: outer_context"
|
@@ -235,13 +244,13 @@ end
|
|
235
244
|
# => "Data: inner_context"
|
236
245
|
|
237
246
|
# with a custom delegation order
|
238
|
-
Symbiont::Executor.evaluate_private(object, Symbiont::KIO) do
|
247
|
+
Symbiont::Executor.evaluate_private(object, context_direction: Symbiont::KIO) do
|
239
248
|
format_data(object_data)
|
240
249
|
end
|
241
250
|
# => "Data: kernel_context"
|
242
251
|
|
243
252
|
# SimpleObject#object_data is a private method (inner_context)
|
244
|
-
Symbiont::Executor.evaluate_private(object, Symbiont::IOK) do
|
253
|
+
Symbiont::Executor.evaluate_private(object, context_direction: Symbiont::IOK) do
|
245
254
|
format_data(object_data)
|
246
255
|
end
|
247
256
|
# => "Data: inner_data"
|
@@ -252,9 +261,9 @@ end
|
|
252
261
|
`Symbiont::Executor` provides the possibility of obtaining the method object with consideration of the chosen delegation order:
|
253
262
|
|
254
263
|
- only public methods:
|
255
|
-
- `public_method(method_name,
|
264
|
+
- `public_method(method_name, *required_contexts, [context_direction:], &clojure)`
|
256
265
|
- public and private methods:
|
257
|
-
- `private_method(method_name,
|
266
|
+
- `private_method(method_name, *required_contexts, [context_direction:], &clojure)`
|
258
267
|
|
259
268
|
If no context is able to respond to the required method - `Symbiont::Trigger::ContextNoMethodError` exception is thrown.
|
260
269
|
|
@@ -268,11 +277,11 @@ Symbiont::Executor.public_method(:object_data, object, &closure)
|
|
268
277
|
# => #<Method: SimpleObject#object_data>
|
269
278
|
|
270
279
|
# with a custom delegation order
|
271
|
-
Symbiont::Executor.public_method(:object_data, object, Symbiont::OIK, &closure)
|
280
|
+
Symbiont::Executor.public_method(:object_data, object, context_direction: Symbiont::OIK, &closure)
|
272
281
|
# => (main) #<Method: SimpleObject(object)#object_data>
|
273
282
|
|
274
283
|
# SimpleObject#object_data is a private method
|
275
|
-
Symbiont::Executor.public_method(:object_data, object, Symbiont::IOK, &closure)
|
284
|
+
Symbiont::Executor.public_method(:object_data, object, context_direction: Symbiont::IOK, &closure)
|
276
285
|
# => (main) #<Method: SimpleObject(object)#object_data>
|
277
286
|
```
|
278
287
|
|
@@ -284,17 +293,17 @@ Symbiont::Executor.private_method(:object_data, object, &clojure)
|
|
284
293
|
# => #<Method: SimpleObject#object_data>
|
285
294
|
|
286
295
|
# with a custom delegation order
|
287
|
-
Symbiont::Executor.private_method(:object_data, object, Symbiont::KIO, &clojure)
|
296
|
+
Symbiont::Executor.private_method(:object_data, object, context_direction: Symbiont::KIO, &clojure)
|
288
297
|
# => #<Method: Kernel.object_data>
|
289
298
|
|
290
299
|
# SimpleObject#object_data is a private_method
|
291
|
-
Symbiont::Executor.private_method(:object_data, object, Symbiotn::IKO, &clojure)
|
300
|
+
Symbiont::Executor.private_method(:object_data, object, context_direction: Symbiotn::IKO, &clojure)
|
292
301
|
# => #<Method: SimpleObject#object_data>
|
293
302
|
```
|
294
303
|
|
295
304
|
## Symbiont Mixin
|
296
305
|
|
297
|
-
|
306
|
+
`Symbiont::Context` is a mixin that allows any object to call proc objects in the context of itself as `Symbiont::Executor`.
|
298
307
|
|
299
308
|
You can specify the default direction of the context delegation. `Symbiont::IOK` is used by default.
|
300
309
|
|
@@ -354,6 +363,33 @@ SimpleObject.new.evaluate(Symbiont::IOK) { object_data }
|
|
354
363
|
# => object.object_data => "inner_context"
|
355
364
|
```
|
356
365
|
|
366
|
+
## Multiple inner contexts
|
367
|
+
|
368
|
+
|
369
|
+
`Symbiont::Executor` allows you to work with multiple inner contexts (can receive a set of objects instead of the one main object).
|
370
|
+
Each object will be used as an inner context in order they are passed.
|
371
|
+
The method will be addressed to the object that responds first (in accordance with a chosen delegation order).
|
372
|
+
|
373
|
+
```ruby
|
374
|
+
# Usage:
|
375
|
+
|
376
|
+
Symbiont::Executor.evaluate(object_a, object_b, context_direction: Symbiont::IOK, &closure)
|
377
|
+
Symbiont::Executor.evaluate_private(object_a, object_b, context_direction: Symbiont::IOK, &closure)
|
378
|
+
Symbiont::Executor.publc_method(:method_name, object_a, object_b, context_direction: Symbiont::IOK, &closure)
|
379
|
+
Symbiont::Executor.private_method(:method_name, object_a, object_b, context_direction: Symbiont::IOK, &closure)
|
380
|
+
|
381
|
+
# Example
|
382
|
+
|
383
|
+
object_a.info # => "object_info"
|
384
|
+
object_b.data # => "object_data"
|
385
|
+
|
386
|
+
closure = proc { "#{info} #{data}" }
|
387
|
+
|
388
|
+
Symbiont::Executor.evaluate(object_a, object_b, &closure) # => "object_info object_data"
|
389
|
+
Symbiont::Executor.public_method(:data, object_a, object_b, &closure).call # => "object_data"
|
390
|
+
Symbiont::Executor.public_method(:info, object_a, object_b, &closure).call # => "object_info"
|
391
|
+
```
|
392
|
+
|
357
393
|
# Contributing
|
358
394
|
|
359
395
|
- Fork it ( https://github.com/0exp/symbiont-ruby/fork )
|
@@ -366,6 +402,9 @@ SimpleObject.new.evaluate(Symbiont::IOK) { object_data }
|
|
366
402
|
|
367
403
|
Released under MIT License.
|
368
404
|
|
369
|
-
#
|
405
|
+
# Authors
|
406
|
+
|
407
|
+
[Logo](https://github.com/0exp/symbiont-ruby/tree/master/logo) was created by **Viktoria Karaulova** (my special thanks ^_^).
|
408
|
+
|
409
|
+
Project was created by **Rustam Ibragimov**.
|
370
410
|
|
371
|
-
Created by Rustam Ibragimov.
|
data/Rakefile
CHANGED
@@ -1,6 +1,30 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
require 'yard'
|
3
6
|
|
4
7
|
RSpec::Core::RakeTask.new(:rspec)
|
5
8
|
|
6
|
-
|
9
|
+
YARD::Rake::YardocTask.new(:doc) do |t|
|
10
|
+
t.files = Dir[Pathname.new(__FILE__).join('../lib/**/*.rb')]
|
11
|
+
t.options = %w[--protected --private]
|
12
|
+
end
|
13
|
+
|
14
|
+
task default: :rspec
|
15
|
+
|
16
|
+
task yardoc: :doc do
|
17
|
+
undocumented_code_objects = YARD::Registry.tap(&:load).select do |code_object|
|
18
|
+
code_object.docstring.empty?
|
19
|
+
end
|
20
|
+
|
21
|
+
if undocumented_code_objects.empty?
|
22
|
+
puts 'YARD COVERAGE [SUCCESS] => 100% documentation coverage!'
|
23
|
+
else
|
24
|
+
failing_code_objects = undocumented_code_objects.map do |code_object|
|
25
|
+
"- #{code_object.class} => #{code_object.to_s}"
|
26
|
+
end.join("\n")
|
27
|
+
|
28
|
+
abort("YARD COVERAGE [FAILURE] => No documentation found for: \n #{failing_code_objects}")
|
29
|
+
end
|
30
|
+
end
|
data/lib/symbiont.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# Main Symbiont namespace.
|
4
|
+
#
|
3
5
|
# @api public
|
4
6
|
# @since 0.1.0
|
5
7
|
module Symbiont
|
@@ -10,32 +12,50 @@ module Symbiont
|
|
10
12
|
require_relative 'symbiont/executor'
|
11
13
|
require_relative 'symbiont/context'
|
12
14
|
|
15
|
+
# Method delegation order alias (inner_contexts => outer_context => kernel_context).
|
16
|
+
#
|
13
17
|
# @see Symbiont::Trigger::IOK
|
18
|
+
#
|
14
19
|
# @api public
|
15
20
|
# @since 0.1.0
|
16
21
|
IOK = Trigger::IOK
|
17
22
|
|
23
|
+
# Method delegation order alias (outer_context => inner_contexts => kernel_context).
|
24
|
+
#
|
18
25
|
# @see Symbiont::Trigger::OIK
|
26
|
+
#
|
19
27
|
# @api public
|
20
28
|
# @since 0.1.0
|
21
29
|
OIK = Trigger::OIK
|
22
30
|
|
31
|
+
# Method delegation order alias (outer_context => kernel_context => inner_contexts).
|
32
|
+
#
|
23
33
|
# @see Symbiont::Trigger::OKI
|
34
|
+
#
|
24
35
|
# @api public
|
25
36
|
# @since 0.1.0
|
26
37
|
OKI = Trigger::OKI
|
27
38
|
|
39
|
+
# Method delegation order alias (inner_contexts => kernel_context => outer_context).
|
40
|
+
#
|
28
41
|
# @see Symbiont::Trigger::IKO
|
42
|
+
#
|
29
43
|
# @api public
|
30
44
|
# @since 0.1.0
|
31
45
|
IKO = Trigger::IKO
|
32
46
|
|
47
|
+
# Method delegation order alias (kernel_context => outer_context => inner_contexts).
|
48
|
+
#
|
33
49
|
# @see Symbiont::Trigger::IOK
|
50
|
+
#
|
34
51
|
# @api public
|
35
52
|
# @since 0.1.0
|
36
53
|
KOI = Trigger::KOI
|
37
54
|
|
55
|
+
# Method delegation order alias (kernel_context => inner_contexts => outer_context).
|
56
|
+
#
|
38
57
|
# @see Symbiont::Trigger::KIO
|
58
|
+
#
|
39
59
|
# @api public
|
40
60
|
# @since 0.1.0
|
41
61
|
KIO = Trigger::KIO
|
data/lib/symbiont/context.rb
CHANGED
@@ -4,9 +4,10 @@ module Symbiont
|
|
4
4
|
class << self
|
5
5
|
# Factory method for a mixin module that provides an ability to invoke procs and lambdas
|
6
6
|
# in many contexts to any object. Mixes up special methods that delegate execution logic to
|
7
|
-
# to a special mediator object (Symbiont::Executor).
|
7
|
+
# to a special mediator object (`Symbiont::Executor`).
|
8
8
|
#
|
9
|
-
# @param default_context_direction [Array<Symbol>]
|
9
|
+
# @param default_context_direction [Array<Symbol>]
|
10
|
+
# Delegation order `for Symbiont::Executor`. Trigger::IOK is used by default.
|
10
11
|
# @return [Module]
|
11
12
|
#
|
12
13
|
# @see Symbiont::Executor
|
@@ -17,32 +18,36 @@ module Symbiont
|
|
17
18
|
# @api public
|
18
19
|
# @since 0.1.0
|
19
20
|
#
|
20
|
-
# rubocop:disable Naming/MethodName
|
21
|
+
# rubocop:disable Naming/MethodName
|
21
22
|
def Context(default_context_direction = Trigger::IOK)
|
22
23
|
Module.new do
|
23
24
|
define_method :evaluate do |context_direction = default_context_direction, &closure|
|
24
|
-
Executor.evaluate(self, context_direction, &closure)
|
25
|
+
Executor.evaluate(self, context_direction: context_direction, &closure)
|
25
26
|
end
|
26
27
|
|
27
28
|
define_method :evaluate_private do |context_direction = default_context_direction, &closure|
|
28
|
-
Executor.evaluate_private(self, context_direction, &closure)
|
29
|
+
Executor.evaluate_private(self, context_direction: context_direction, &closure)
|
29
30
|
end
|
30
31
|
|
31
32
|
define_method :public_method do |method_name, context_direction = default_context_direction, &closure|
|
32
|
-
Executor.public_method(self, method_name, context_direction, &closure)
|
33
|
+
Executor.public_method(self, method_name, context_direction: context_direction, &closure)
|
33
34
|
end
|
34
35
|
|
35
36
|
define_method :private_method do |method_name, context_direction = default_context_direction, &closure|
|
36
|
-
Executor.private_method(self, method_name, context_direction, &closure)
|
37
|
+
Executor.private_method(self, method_name, context_direction: context_direction, &closure)
|
37
38
|
end
|
38
39
|
end
|
39
40
|
end
|
40
|
-
# rubocop:enable Naming/MethodName
|
41
|
+
# rubocop:enable Naming/MethodName
|
41
42
|
end
|
42
43
|
|
44
|
+
# Default Context mixin that provides an ability to invoke procs and lambdas
|
45
|
+
# in many contexts to any object. Mixes up special methods that delegate execution logic to
|
46
|
+
# to a special mediator object (`Symbiont::Executor`). Uses Symbiont::Trigger::IOK delegation order.
|
47
|
+
#
|
43
48
|
# @see Symbiont.Context
|
44
49
|
#
|
45
50
|
# @api public
|
46
51
|
# @since 0.1.0
|
47
|
-
Context = Context()
|
52
|
+
Context = Context(Trigger::IOK)
|
48
53
|
end
|
data/lib/symbiont/executor.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Symbiont
|
4
4
|
# Mediator service object that controls the logic of creating triggers and calling them.
|
5
|
-
# Acts as a factory for trigerrs and
|
5
|
+
# Acts as a factory for trigerrs and an execution-mediator for procs.
|
6
6
|
#
|
7
7
|
# @api public
|
8
8
|
# @since 0.1.0
|
@@ -11,40 +11,74 @@ module Symbiont
|
|
11
11
|
# Starts execution of a proc object in the context of the passed object with the selected
|
12
12
|
# direction of method dispatching. Delegates execution to a public trigger.
|
13
13
|
#
|
14
|
-
# @param
|
14
|
+
# @param required_contexts [Array<Object>]
|
15
|
+
# A set of objects that should be used as the main context series for method resolving
|
16
|
+
# algorithm.
|
15
17
|
# @param context_direction [Array<Symbol>]
|
18
|
+
# An array of symbols that represents the direction of contexts. Possible values:
|
19
|
+
#
|
20
|
+
# - Symbiont::IOK
|
21
|
+
# - Symbiont::OIK
|
22
|
+
# - Symbiont::OKI
|
23
|
+
# - Symbiont::IKO
|
24
|
+
# - Symbiont::KOI
|
25
|
+
# - Symbiont::KIO
|
16
26
|
# @param closure [Proc]
|
27
|
+
# Proc object that will be evaluated in many contexts: initial, outer and kernel.
|
17
28
|
# @return void
|
18
29
|
#
|
19
30
|
# @see Symbiont::Trigger#__evaluate__
|
20
31
|
#
|
21
32
|
# @api public
|
22
33
|
# @since 0.1.0
|
23
|
-
def evaluate(
|
24
|
-
public_trigger(
|
34
|
+
def evaluate(*required_contexts, context_direction: Trigger::IOK, &closure)
|
35
|
+
public_trigger(*required_contexts, context_direction: context_direction, &closure).__evaluate__
|
25
36
|
end
|
26
37
|
|
27
38
|
# Starts execution of a proc object in the context of the passed object with the selected
|
28
39
|
# direction of method dispatching. Delegates execution to a private trigger.
|
29
40
|
#
|
30
|
-
# @param
|
41
|
+
# @param required_contexts [Array<Object>]
|
42
|
+
# A set of objects that should be used as the main context series for method resolving
|
43
|
+
# algorithm.
|
31
44
|
# @param context_direction [Array<Symbol>]
|
45
|
+
# An array of symbols that represents the direction of contexts. Possible values:
|
46
|
+
#
|
47
|
+
# - Symbiont::IOK
|
48
|
+
# - Symbiont::OIK
|
49
|
+
# - Symbiont::OKI
|
50
|
+
# - Symbiont::IKO
|
51
|
+
# - Symbiont::KOI
|
52
|
+
# - Symbiont::KIO
|
32
53
|
# @param closure [Proc]
|
54
|
+
# Proc object that will be evaluated in many contexts: initial, outer and kernel.
|
33
55
|
# @return void
|
34
56
|
#
|
35
57
|
# @see Symbiont::Trigger#__evaluate__
|
36
58
|
#
|
37
59
|
# @api public
|
38
60
|
# @since 0.1.0
|
39
|
-
def evaluate_private(
|
40
|
-
private_trigger(
|
61
|
+
def evaluate_private(*required_contexts, context_direction: Trigger::IOK, &closure)
|
62
|
+
private_trigger(*required_contexts, context_direction: context_direction, &closure).__evaluate__
|
41
63
|
end
|
42
64
|
|
43
65
|
# Factory method that instantiates a public trigger with the desired execution context,
|
44
66
|
# the direction of method dispatching and the closure that needs to be performed.
|
45
67
|
#
|
68
|
+
# @param required_contexts [Array<Object>]
|
69
|
+
# A set of objects that should be used as the main context series for method resolving
|
70
|
+
# algorithm.
|
46
71
|
# @param context_direction [Array<Symbol>]
|
72
|
+
# An array of symbols that represents the direction of contexts. Possible values:
|
73
|
+
#
|
74
|
+
# - Symbiont::IOK
|
75
|
+
# - Symbiont::OIK
|
76
|
+
# - Symbiont::OKI
|
77
|
+
# - Symbiont::IKO
|
78
|
+
# - Symbiont::KOI
|
79
|
+
# - Symbiont::KIO
|
47
80
|
# @param closure [Proc]
|
81
|
+
# Proc object that will be evaluated in many contexts: initial, outer and kernel.
|
48
82
|
# @return [Symbiont::PublicTrigger]
|
49
83
|
#
|
50
84
|
# @see Symbiont::PublicTrigger
|
@@ -52,16 +86,27 @@ module Symbiont
|
|
52
86
|
#
|
53
87
|
# @api public
|
54
88
|
# @since 0.1.0
|
55
|
-
def public_trigger(
|
56
|
-
PublicTrigger.new(
|
89
|
+
def public_trigger(*required_contexts, context_direction: Trigger::IOK, &closure)
|
90
|
+
PublicTrigger.new(*required_contexts, context_direction: context_direction, &closure)
|
57
91
|
end
|
58
92
|
|
59
93
|
# Factory method that instantiates a private trigger with the desired execution context,
|
60
94
|
# the direction of method dispatching and the closure that needs to be performed.
|
61
95
|
#
|
62
|
-
# @param
|
96
|
+
# @param required_contexts [Array<Object>]
|
97
|
+
# A set of objects that should be used as the main context series for method resolving
|
98
|
+
# algorithm.
|
63
99
|
# @param context_direction [Array<Symbol>]
|
100
|
+
# An array of symbols that represents the direction of contexts. Possible values:
|
101
|
+
#
|
102
|
+
# - Symbiont::IOK
|
103
|
+
# - Symbiont::OIK
|
104
|
+
# - Symbiont::OKI
|
105
|
+
# - Symbiont::IKO
|
106
|
+
# - Symbiont::KOI
|
107
|
+
# - Symbiont::KIO
|
64
108
|
# @param closure [Proc]
|
109
|
+
# Proc object that will be evaluated in many contexts: initial, outer and kernel.
|
65
110
|
# @return [Symbiont::PrivateTrigger]
|
66
111
|
#
|
67
112
|
# @see Symbiont::PrivateTrigger
|
@@ -69,42 +114,62 @@ module Symbiont
|
|
69
114
|
#
|
70
115
|
# @api public
|
71
116
|
# @since 0.1.0
|
72
|
-
def private_trigger(
|
73
|
-
PrivateTrigger.new(
|
117
|
+
def private_trigger(*required_contexts, context_direction: Trigger::IOK, &closure)
|
118
|
+
PrivateTrigger.new(*required_contexts, context_direction: context_direction, &closure)
|
74
119
|
end
|
75
120
|
|
76
121
|
# Gets the method object taken from the context that can respond to it.
|
77
122
|
# Considers only public methods.
|
78
123
|
#
|
79
|
-
# @param method_name [Symbol,String]
|
80
|
-
# @param
|
81
|
-
#
|
82
|
-
#
|
124
|
+
# @param method_name [Symbol,String] A name of required method.
|
125
|
+
# @param required_contexts [Array<Object>]
|
126
|
+
# A set of objects that should be used as the main context series for method resolving
|
127
|
+
# algorithm.
|
128
|
+
# An array of symbols that represents the direction of contexts. Possible values:
|
129
|
+
#
|
130
|
+
# - Symbiont::IOK
|
131
|
+
# - Symbiont::OIK
|
132
|
+
# - Symbiont::OKI
|
133
|
+
# - Symbiont::IKO
|
134
|
+
# - Symbiont::KOI
|
135
|
+
# - Symbiont::KIO
|
136
|
+
# @param closure [Proc] Proc object that will be used as outer-context for method resolution.
|
83
137
|
# @return [Method]
|
84
138
|
#
|
139
|
+
# @see Symbiont::PublicTrigger
|
85
140
|
# @see Symbiont::Trigger#method
|
86
141
|
#
|
87
142
|
# @api public
|
88
143
|
# @since 0.1.0
|
89
|
-
def public_method(method_name,
|
90
|
-
public_trigger(
|
144
|
+
def public_method(method_name, *required_contexts, context_direction: Trigger::IOK, &closure)
|
145
|
+
public_trigger(*required_contexts, context_direction: context_direction, &closure).method(method_name)
|
91
146
|
end
|
92
147
|
|
93
148
|
# Gets the method object taken from the context that can respond to it.
|
94
149
|
# Considers private methods and public methods.
|
95
150
|
#
|
96
|
-
# @param method_name [Symbol,String]
|
97
|
-
# @param
|
98
|
-
#
|
99
|
-
#
|
151
|
+
# @param method_name [Symbol,String] A name of required method.
|
152
|
+
# @param required_contexts [Array<Object>]
|
153
|
+
# A set of objects that should be used as the main context series for method resolving
|
154
|
+
# algorithm.
|
155
|
+
# An array of symbols that represents the direction of contexts. Possible values:
|
156
|
+
#
|
157
|
+
# - Symbiont::IOK
|
158
|
+
# - Symbiont::OIK
|
159
|
+
# - Symbiont::OKI
|
160
|
+
# - Symbiont::IKO
|
161
|
+
# - Symbiont::KOI
|
162
|
+
# - Symbiont::KIO
|
163
|
+
# @param closure [Proc] Proc object that will be used as outer-context for method resolution.
|
100
164
|
# @return [Method]
|
101
165
|
#
|
166
|
+
# @see Symbiont::PrivateTrigger
|
102
167
|
# @see Symbiont::Trigger#method
|
103
168
|
#
|
104
169
|
# @api public
|
105
170
|
# @since 0.1.0
|
106
|
-
def private_method(method_name,
|
107
|
-
private_trigger(
|
171
|
+
def private_method(method_name, *required_contexts, context_direction: Trigger::IOK, &closure)
|
172
|
+
private_trigger(*required_contexts, context_direction: context_direction, &closure).method(method_name)
|
108
173
|
end
|
109
174
|
end
|
110
175
|
end
|