symbiont-ruby 0.2.0 → 0.7.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 +5 -5
- data/.gitignore +1 -1
- data/.rspec +1 -1
- data/.rubocop.yml +17 -112
- data/CHANGELOG.md +32 -0
- data/Gemfile +4 -2
- data/Gemfile.lock +130 -0
- data/LICENSE.txt +1 -1
- data/README.md +70 -30
- data/Rakefile +15 -1
- data/Steepfile +6 -0
- data/bin/console +2 -1
- data/lib/symbiont.rb +1 -0
- data/lib/symbiont/executor.rb +8 -60
- data/lib/symbiont/isolator.rb +185 -0
- data/lib/symbiont/private_trigger.rb +41 -2
- data/lib/symbiont/public_trigger.rb +40 -1
- data/lib/symbiont/teleport.rb +9 -0
- data/lib/symbiont/trigger.rb +20 -5
- data/lib/symbiont/version.rb +1 -1
- data/sig/.keep +0 -0
- data/symbiont-ruby.gemspec +12 -10
- metadata +29 -27
- data/.hound.yml +0 -2
- data/.travis.yml +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6714f1b3ec4728993c6142a6c1c2afb74fa47bbddb6bd24ba0f07400d1a8dc2a
|
4
|
+
data.tar.gz: bd261c826def843dea5411a74c95e342b2c5eff9d657750c97b7e3369e29c599
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9611312a09174b8c326061d235bc7f89fbb4a3dc5ceed382210a94a9ece33811f3a164be5ea3718624b4de6b1361014740957727fded344eb4649d9da056847
|
7
|
+
data.tar.gz: d398c976b32b14caf11b80d9fd2ab7b026b4e71429f9bdf3c966f611b4f70dfc30bf48a89f008e2d095df2b19a9dd2b82ab66bc1ad181ad46b98f0379de57e94
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,125 +1,30 @@
|
|
1
|
-
|
1
|
+
inherit_gem:
|
2
|
+
armitage-rubocop:
|
3
|
+
- lib/rubocop.general.yml
|
4
|
+
- lib/rubocop.rspec.yml
|
2
5
|
|
3
6
|
AllCops:
|
4
|
-
|
5
|
-
DisplayStyleGuide: true
|
6
|
-
TargetRubyVersion: 2.4.3
|
7
|
+
TargetRubyVersion: 3.0.0
|
7
8
|
Include:
|
8
|
-
- lib
|
9
|
-
- spec
|
10
|
-
|
11
|
-
- bin/**/*
|
12
|
-
- Gemfile
|
9
|
+
- lib/**/*.rb
|
10
|
+
- spec/**/*.rb
|
11
|
+
- bin/console
|
13
12
|
- Rakefile
|
13
|
+
- Gemfile
|
14
14
|
- symbiont-ruby.gemspec
|
15
|
+
- Steepfile
|
15
16
|
|
16
|
-
|
17
|
-
Exclude:
|
18
|
-
- spec/**/*
|
19
|
-
|
20
|
-
Style/RescueModifier:
|
21
|
-
Exclude:
|
22
|
-
- spec/**/*
|
23
|
-
|
24
|
-
Style/AsciiComments:
|
25
|
-
Enabled: false
|
26
|
-
|
27
|
-
Style/Alias:
|
28
|
-
Enabled: false
|
29
|
-
|
30
|
-
Style/GuardClause:
|
31
|
-
Enabled: false
|
32
|
-
|
33
|
-
Style/DoubleNegation:
|
34
|
-
Enabled: false
|
35
|
-
|
36
|
-
Style/Documentation:
|
37
|
-
Enabled: false
|
38
|
-
|
39
|
-
Style/ClassAndModuleChildren:
|
40
|
-
Enabled: false
|
41
|
-
|
42
|
-
Style/IfUnlessModifier:
|
43
|
-
Enabled: false
|
44
|
-
|
45
|
-
Style/EmptyCaseCondition:
|
46
|
-
Enabled: false
|
47
|
-
|
48
|
-
Style/FrozenStringLiteralComment:
|
49
|
-
Enabled: true
|
50
|
-
|
51
|
-
Style/InverseMethods:
|
52
|
-
Enabled: false
|
53
|
-
|
54
|
-
Style/ParallelAssignment:
|
55
|
-
Enabled: false
|
56
|
-
|
57
|
-
Style/CommentedKeyword:
|
58
|
-
Enabled: false
|
59
|
-
|
60
|
-
Lint/HandleExceptions:
|
61
|
-
Enabled: false
|
62
|
-
|
63
|
-
Layout/IndentArray:
|
64
|
-
Enabled: false
|
65
|
-
|
66
|
-
Lint/AmbiguousRegexpLiteral:
|
67
|
-
Enabled: false
|
68
|
-
|
69
|
-
Lint/UnusedMethodArgument:
|
70
|
-
Enabled: false
|
71
|
-
|
72
|
-
Naming/FileName:
|
73
|
-
Enabled: false
|
74
|
-
|
75
|
-
Naming/VariableNumber:
|
76
|
-
EnforcedStyle: snake_case
|
77
|
-
|
78
|
-
Metrics/LineLength:
|
17
|
+
Layout/LineLength:
|
79
18
|
Max: 120
|
80
19
|
|
81
|
-
|
20
|
+
# NOTE: for code examples in tests
|
21
|
+
Lint/EmptyBlock:
|
82
22
|
Exclude:
|
83
|
-
- spec
|
84
|
-
|
85
|
-
Metrics/CyclomaticComplexity:
|
86
|
-
Max: 10
|
87
|
-
|
88
|
-
Metrics/PerceivedComplexity:
|
89
|
-
Max: 10
|
90
|
-
|
91
|
-
Metrics/MethodLength:
|
92
|
-
Max: 20
|
93
|
-
|
94
|
-
RSpec/ContextWording:
|
95
|
-
Enabled: false
|
96
|
-
|
97
|
-
RSpec/HookArgument:
|
98
|
-
Enabled: false
|
99
|
-
|
100
|
-
RSpec/NestedGroups:
|
101
|
-
Max: 6
|
102
|
-
|
103
|
-
RSpec/MessageSpies:
|
104
|
-
Enabled: false
|
105
|
-
|
106
|
-
RSpec/ExampleLength:
|
107
|
-
Enabled: false
|
108
|
-
|
109
|
-
RSpec/MultipleExpectations:
|
110
|
-
Enabled: false
|
111
|
-
|
112
|
-
RSpec/DescribeClass:
|
113
|
-
Enabled: false
|
114
|
-
|
115
|
-
RSpec/LetSetup:
|
116
|
-
Enabled: false
|
117
|
-
|
118
|
-
RSpec/AnyInstance:
|
119
|
-
Enabled: false
|
23
|
+
- spec/**/*.rb
|
120
24
|
|
121
|
-
|
25
|
+
Style/RedundantBegin:
|
122
26
|
Enabled: false
|
123
27
|
|
124
|
-
|
28
|
+
# NOTE: for code clarity in tests
|
29
|
+
RSpec/LeakyConstantDeclaration:
|
125
30
|
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,38 @@
|
|
1
1
|
# Changelog
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## [0.7.0] 2021-06-22
|
5
|
+
### Added
|
6
|
+
- Support for Ruby@2.7.2, Ruby@3.0.0;
|
7
|
+
|
8
|
+
### Changed
|
9
|
+
- No more `TravisCI` (TODO: migrate to `Github Actions`);
|
10
|
+
- Updated development dependencies;
|
11
|
+
|
12
|
+
## [0.6.0] 2018-03-28
|
13
|
+
### Changed
|
14
|
+
- Removed verbose code from `#__actual_context__` and `#method` methods of
|
15
|
+
`Symbiont::PublicTrigger` and `Symbiont::PrivateTrigger` classes.
|
16
|
+
|
17
|
+
## [0.5.0] 2018-03-28
|
18
|
+
### Added
|
19
|
+
- Support for method dispatching for `BasicObject` instances (which does not support `#respond_to?` method);
|
20
|
+
- Support for method extracting for `BasicObject` instances (which does not support `#method` method);
|
21
|
+
- Updated development dependencies;
|
22
|
+
- Support for `Ruby@2.6.2`, `Ruby@2.5.5`;
|
23
|
+
|
24
|
+
## [0.4.0] 2018-10-25
|
25
|
+
### Added
|
26
|
+
- Support for Ruby@2.5.3, Ruby@2.4.5, Ruby@2.3.8;
|
27
|
+
- Updated development dependencies;
|
28
|
+
|
29
|
+
### Changed
|
30
|
+
- End of Ruby@2.2;
|
31
|
+
|
32
|
+
## [0.3.0] 2018-06-15
|
33
|
+
### Added
|
34
|
+
- `Symbiont::Isolator` - proc object isolation layer for delayed invocations;
|
35
|
+
|
4
36
|
## [0.2.0] 2018-04-22
|
5
37
|
### Added
|
6
38
|
- Logo ^_^ (special thanks to **Viktoria Karaulova**)
|
data/Gemfile
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
4
6
|
|
5
7
|
# Specify your gem's dependencies in symbiont-ruby.gemspec
|
6
8
|
gemspec
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
symbiont-ruby (0.7.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activesupport (6.1.3.2)
|
10
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
11
|
+
i18n (>= 1.6, < 2)
|
12
|
+
minitest (>= 5.1)
|
13
|
+
tzinfo (~> 2.0)
|
14
|
+
zeitwerk (~> 2.3)
|
15
|
+
armitage-rubocop (1.10.0)
|
16
|
+
rubocop (= 1.10.0)
|
17
|
+
rubocop-performance (= 1.9.2)
|
18
|
+
rubocop-rails (= 2.9.1)
|
19
|
+
rubocop-rake (= 0.5.1)
|
20
|
+
rubocop-rspec (= 2.2.0)
|
21
|
+
ast (2.4.2)
|
22
|
+
coderay (1.1.3)
|
23
|
+
concurrent-ruby (1.1.9)
|
24
|
+
diff-lcs (1.4.4)
|
25
|
+
docile (1.4.0)
|
26
|
+
ffi (1.15.3)
|
27
|
+
i18n (1.8.10)
|
28
|
+
concurrent-ruby (~> 1.0)
|
29
|
+
language_server-protocol (3.16.0.1)
|
30
|
+
listen (3.5.1)
|
31
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
32
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
33
|
+
method_source (1.0.0)
|
34
|
+
minitest (5.14.4)
|
35
|
+
parallel (1.20.1)
|
36
|
+
parser (3.0.1.1)
|
37
|
+
ast (~> 2.4.1)
|
38
|
+
pry (0.14.1)
|
39
|
+
coderay (~> 1.1)
|
40
|
+
method_source (~> 1.0)
|
41
|
+
rack (2.2.3)
|
42
|
+
rainbow (3.0.0)
|
43
|
+
rake (13.0.3)
|
44
|
+
rb-fsevent (0.11.0)
|
45
|
+
rb-inotify (0.10.1)
|
46
|
+
ffi (~> 1.0)
|
47
|
+
rbs (1.2.1)
|
48
|
+
regexp_parser (2.1.1)
|
49
|
+
rexml (3.2.5)
|
50
|
+
rspec (3.10.0)
|
51
|
+
rspec-core (~> 3.10.0)
|
52
|
+
rspec-expectations (~> 3.10.0)
|
53
|
+
rspec-mocks (~> 3.10.0)
|
54
|
+
rspec-core (3.10.1)
|
55
|
+
rspec-support (~> 3.10.0)
|
56
|
+
rspec-expectations (3.10.1)
|
57
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
58
|
+
rspec-support (~> 3.10.0)
|
59
|
+
rspec-mocks (3.10.2)
|
60
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
61
|
+
rspec-support (~> 3.10.0)
|
62
|
+
rspec-support (3.10.2)
|
63
|
+
rubocop (1.10.0)
|
64
|
+
parallel (~> 1.10)
|
65
|
+
parser (>= 3.0.0.0)
|
66
|
+
rainbow (>= 2.2.2, < 4.0)
|
67
|
+
regexp_parser (>= 1.8, < 3.0)
|
68
|
+
rexml
|
69
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
70
|
+
ruby-progressbar (~> 1.7)
|
71
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
72
|
+
rubocop-ast (1.7.0)
|
73
|
+
parser (>= 3.0.1.1)
|
74
|
+
rubocop-performance (1.9.2)
|
75
|
+
rubocop (>= 0.90.0, < 2.0)
|
76
|
+
rubocop-ast (>= 0.4.0)
|
77
|
+
rubocop-rails (2.9.1)
|
78
|
+
activesupport (>= 4.2.0)
|
79
|
+
rack (>= 1.1)
|
80
|
+
rubocop (>= 0.90.0, < 2.0)
|
81
|
+
rubocop-rake (0.5.1)
|
82
|
+
rubocop
|
83
|
+
rubocop-rspec (2.2.0)
|
84
|
+
rubocop (~> 1.0)
|
85
|
+
rubocop-ast (>= 1.1.0)
|
86
|
+
ruby-progressbar (1.11.0)
|
87
|
+
simplecov (0.21.2)
|
88
|
+
docile (~> 1.1)
|
89
|
+
simplecov-html (~> 0.11)
|
90
|
+
simplecov_json_formatter (~> 0.1)
|
91
|
+
simplecov-html (0.12.3)
|
92
|
+
simplecov_json_formatter (0.1.3)
|
93
|
+
steep (0.44.1)
|
94
|
+
activesupport (>= 5.1)
|
95
|
+
language_server-protocol (>= 3.15, < 4.0)
|
96
|
+
listen (~> 3.0)
|
97
|
+
parallel (>= 1.0.0)
|
98
|
+
parser (>= 2.7)
|
99
|
+
rainbow (>= 2.2.2, < 4.0)
|
100
|
+
rbs (>= 1.2.0)
|
101
|
+
terminal-table (>= 2, < 4)
|
102
|
+
terminal-table (3.0.1)
|
103
|
+
unicode-display_width (>= 1.1.1, < 3)
|
104
|
+
typeprof (0.14.1)
|
105
|
+
rbs (>= 1.2.0)
|
106
|
+
tzinfo (2.0.4)
|
107
|
+
concurrent-ruby (~> 1.0)
|
108
|
+
unicode-display_width (2.0.0)
|
109
|
+
yard (0.9.26)
|
110
|
+
zeitwerk (2.4.2)
|
111
|
+
|
112
|
+
PLATFORMS
|
113
|
+
ruby
|
114
|
+
x86_64-darwin-20
|
115
|
+
|
116
|
+
DEPENDENCIES
|
117
|
+
armitage-rubocop (~> 1.8)
|
118
|
+
bundler
|
119
|
+
pry
|
120
|
+
rake
|
121
|
+
rbs (~> 1.0)
|
122
|
+
rspec (~> 3.10)
|
123
|
+
simplecov (~> 0.21)
|
124
|
+
steep (~> 0.40)
|
125
|
+
symbiont-ruby!
|
126
|
+
typeprof (~> 0.12)
|
127
|
+
yard
|
128
|
+
|
129
|
+
BUNDLED WITH
|
130
|
+
2.2.20
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -3,15 +3,13 @@
|
|
3
3
|
<h1 align="center">
|
4
4
|
Symbiont<br />
|
5
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
6
|
</h1>
|
9
7
|
</p>
|
10
8
|
|
11
9
|
**Symbiont** is a cool implementation of proc-objects execution algorithm: in the context of other object,
|
12
|
-
but with the preservation of the
|
10
|
+
but with the preservation of the captured environment of the proc object and with the ability of control the method dispatch
|
13
11
|
inside it. A proc object is executed in three contexts: in the context of required object, in the context of
|
14
|
-
a
|
12
|
+
a captured proc's environment and in the global (Kernel) context.
|
15
13
|
|
16
14
|
# Installation
|
17
15
|
|
@@ -45,7 +43,7 @@ require 'symbiont'
|
|
45
43
|
- [Usage](#usage)
|
46
44
|
- [Context management](#context-management)
|
47
45
|
- [Supported method delegation directions](#supported-methods-delegation-directions)
|
48
|
-
- [Proc object
|
46
|
+
- [Proc object invocation](#proc-object-invocation)
|
49
47
|
- [Considering public methods only (.evaluate)](#considering-public-methods-only-evaluate)
|
50
48
|
- [Considering private and public methods (.evaluate_private)](#considering-private-and-public-methods-evaluate_private)
|
51
49
|
- [Getting method-objects (Method)](#getting-method-objects-method)
|
@@ -55,18 +53,19 @@ require 'symbiont'
|
|
55
53
|
- [Mixing a module with default delegation direction](#mixing-a-module-with-default-delegation-direction)
|
56
54
|
- [Mixing a module with certain delegation direction](#mixing-a-module-with-certain-delegation-direction)
|
57
55
|
- [Multiple inner contexts](#multiple-inner-contexts)
|
56
|
+
- [Isolator - proc object isolation layer for delayed invocations](#isolator---proc-object-isolation-layer-for-delayed-invocations)
|
58
57
|
|
59
58
|
# Problems and motivaiton
|
60
59
|
|
61
60
|
The main problem of `instance_eval` / `instance exec` / `class_eval` / `class_exec` is that the binding (self)
|
62
|
-
inside a proc-
|
63
|
-
But this leads to the fact that the proc object loses access to the original
|
64
|
-
Symbiont solves this problem by allowing
|
61
|
+
inside a proc-object is replaced with the object in where a proc object is executed. This allows you to delegate all methods captured by a proc to another object.
|
62
|
+
But this leads to the fact that the proc object loses access to the original captured environment.
|
63
|
+
Symbiont solves this problem by allowing the proc to be executed in the required context while maintaining access to the methods of the captured environment
|
65
64
|
(including the global context).
|
66
65
|
|
67
66
|
---
|
68
67
|
|
69
|
-
A
|
68
|
+
A problem with `instance_eval` / `instance_exec` / `class_eval` / `class_exec`:
|
70
69
|
|
71
70
|
```ruby
|
72
71
|
class TableFactory
|
@@ -83,7 +82,7 @@ class Migration
|
|
83
82
|
class << self
|
84
83
|
def create_table(&block)
|
85
84
|
TableFactory.new.tap do |table|
|
86
|
-
table.instance_eval(&block) # NOTE: closure
|
85
|
+
table.instance_eval(&block) # NOTE: closure invocation
|
87
86
|
end
|
88
87
|
end
|
89
88
|
end
|
@@ -116,7 +115,7 @@ class Migration
|
|
116
115
|
class << self
|
117
116
|
def create_table(&block)
|
118
117
|
TableFactory.new.tap do |table|
|
119
|
-
Symbiont::Executor.evaluate(table, &block) # NOTE: intercept closure
|
118
|
+
Symbiont::Executor.evaluate(table, &block) # NOTE: intercept closure invocation by Symbiont
|
120
119
|
end
|
121
120
|
end
|
122
121
|
end
|
@@ -137,15 +136,15 @@ Proc-object is executed in three contexts at the same time:
|
|
137
136
|
Methods (called internally) are delegated to the context that is first able to respond.
|
138
137
|
The order of context selection depends on the corresponding context direction parameter.
|
139
138
|
By default the delegation order is: object context => closure context => global context.
|
140
|
-
If no context is able to respond to the method, an exception is
|
141
|
-
Symbiont can consider the
|
139
|
+
If no context is able to respond to the method, an exception is raised (`Symbiont::Trigger::ContextNoMethodError`).
|
140
|
+
Symbiont can consider the visibility of methods when executing.
|
142
141
|
|
143
142
|
|
144
143
|
# Usage
|
145
144
|
|
146
145
|
## Context management
|
147
146
|
|
148
|
-
Imagine
|
147
|
+
Imagine having the following code and the corresponding clojure in the real application:
|
149
148
|
|
150
149
|
```ruby
|
151
150
|
def object_data
|
@@ -177,16 +176,15 @@ How a proc object will be processed, which context will be selected, how to make
|
|
177
176
|
|
178
177
|
## Supported methods delegation directions
|
179
178
|
|
180
|
-
Delegation order
|
181
|
-
and the
|
179
|
+
Delegation order might be passed as a parameter to the proc execution
|
180
|
+
and to the special mixin module, allowing any class or instance to become a symbiont.
|
182
181
|
|
183
|
-
Supported contexts
|
182
|
+
- Supported contexts:
|
183
|
+
- inner context - an object where proc is executed;
|
184
|
+
- outer context - external environment of the proc object;
|
185
|
+
- kernel context - global Kernel context.
|
184
186
|
|
185
|
-
|
186
|
-
- outer context - external environment of the proc object;
|
187
|
-
- kernel context - global Kernel context.
|
188
|
-
|
189
|
-
Symbiont::IOK is chosen by default (`inner context => outer context => kernel context`)
|
187
|
+
Symbiont::IOK is chosen by default (`inner context => outer context => kernel context`).
|
190
188
|
|
191
189
|
```ruby
|
192
190
|
Symbiont::IOK # Inner Context => Outer Context => Kernel Context (DEFAULT)
|
@@ -197,7 +195,7 @@ Symbiont::KOI # Kernel Context => Outer Context => Inner Context
|
|
197
195
|
Symbiont::KIO # Kernel Context => Inner Context => Outer Context
|
198
196
|
```
|
199
197
|
|
200
|
-
## Proc object
|
198
|
+
## Proc object invocation
|
201
199
|
|
202
200
|
`Symbiont::Executor` allows you to execute proc objects in two modes of the delegation:
|
203
201
|
|
@@ -206,11 +204,11 @@ Symbiont::KIO # Kernel Context => Inner Context => Outer Context
|
|
206
204
|
- public and private methods:
|
207
205
|
- `evaluate_private(*required_contexts, [context_direction:], &closure)`
|
208
206
|
|
209
|
-
If
|
207
|
+
If none of contexts is able to respond to the required method - `Symbiont::Trigger::ContextNoMethodError` exception is raised.
|
210
208
|
|
211
|
-
In the case
|
209
|
+
In the case an unsupported direction value is used - `Symbiont::Trigger::IncompatibleContextDirectionError` exception is raised.
|
212
210
|
|
213
|
-
If proc object
|
211
|
+
If proc object isn't passed to the executor - `Symbiont::Trigger::UnprovidedClosureAttributeError` exception is raised.
|
214
212
|
|
215
213
|
#### Considering public methods only (.evaluate)
|
216
214
|
|
@@ -265,9 +263,9 @@ end
|
|
265
263
|
- public and private methods:
|
266
264
|
- `private_method(method_name, *required_contexts, [context_direction:], &clojure)`
|
267
265
|
|
268
|
-
If
|
266
|
+
If none of contexts is able to respond to the required method - `Symbiont::Trigger::ContextNoMethodError` exception is raised.
|
269
267
|
|
270
|
-
In the case
|
268
|
+
In the case an unsupported direction value is used - `Symbiont::Trigger::IncompatibleContextDirectionError` exception is raised.
|
271
269
|
|
272
270
|
#### Considering public methods only (.public_method)
|
273
271
|
|
@@ -305,7 +303,7 @@ Symbiont::Executor.private_method(:object_data, object, context_direction: Symbi
|
|
305
303
|
|
306
304
|
`Symbiont::Context` is a mixin that allows any object to call proc objects in the context of itself as `Symbiont::Executor`.
|
307
305
|
|
308
|
-
You can specify the
|
306
|
+
You can specify the direction of the context delegation. `Symbiont::IOK` is used by default.
|
309
307
|
|
310
308
|
#### Mixing a module with default delegation direction
|
311
309
|
|
@@ -368,7 +366,7 @@ SimpleObject.new.evaluate(Symbiont::IOK) { object_data }
|
|
368
366
|
|
369
367
|
`Symbiont::Executor` allows you to work with multiple inner contexts (can receive a set of objects instead of the one main object).
|
370
368
|
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 (
|
369
|
+
The method will be addressed to the object that responds first (according to a chosen delegation order).
|
372
370
|
|
373
371
|
```ruby
|
374
372
|
# Usage:
|
@@ -390,6 +388,48 @@ Symbiont::Executor.public_method(:data, object_a, object_b, &closure).call # =>
|
|
390
388
|
Symbiont::Executor.public_method(:info, object_a, object_b, &closure).call # => "object_info"
|
391
389
|
```
|
392
390
|
|
391
|
+
## Isolator - proc object isolation layer for delayed invocations
|
392
|
+
|
393
|
+
`Symbiont::Isolator` is a special object that wraps your proc object from any place and provides
|
394
|
+
an ability to invoke this proc object lazily inside an any series of contexts.
|
395
|
+
All `Symbiont::Executor` features are supported (by the way, `Symbiont::Executor`
|
396
|
+
uses `Symbiont::Isolator` under the hood).
|
397
|
+
|
398
|
+
```ruby
|
399
|
+
# Usage:
|
400
|
+
|
401
|
+
# with default direction (Symbiont::IOK)
|
402
|
+
isolator = Symbiont::Isolator.new { call_any_method }
|
403
|
+
|
404
|
+
# with custom direction
|
405
|
+
isolator = Symbiont::Isolator.new(default_direction: Symbiont::KIO) { call_any_method }
|
406
|
+
|
407
|
+
# invocation
|
408
|
+
isolator.evaluate(object_a, object_b) # use default direction defined on instantiation
|
409
|
+
isolator.evaluate(object_a, object_b, direction: Symbiont::KOI) # use custom direction
|
410
|
+
# same for #.evaluate_private
|
411
|
+
|
412
|
+
# getting a method object
|
413
|
+
isolator.public_method(:call_any_method, object_a, object_b) # use default direction defined on instantiation
|
414
|
+
isolator.public_method(:call_any_method, object_a, object_b, direction: Symbiont::KIO) # use custom direction
|
415
|
+
isolator.private_method(...)
|
416
|
+
# same for #.private_method
|
417
|
+
```
|
418
|
+
|
419
|
+
# Roadmap
|
420
|
+
|
421
|
+
- support for toplevel context (`TOPLEVEL_BINDING`);
|
422
|
+
- `fiber teleports`;
|
423
|
+
- official support for **Ruby@3**;
|
424
|
+
|
425
|
+
# Build
|
426
|
+
|
427
|
+
```shell
|
428
|
+
bundle exec rake rubocop
|
429
|
+
bundle exec rake yardoc
|
430
|
+
bundle exec rake rspec
|
431
|
+
```
|
432
|
+
|
393
433
|
# Contributing
|
394
434
|
|
395
435
|
- Fork it ( https://github.com/0exp/symbiont-ruby/fork )
|