symbiont-ruby 0.2.0 → 0.3.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
- SHA1:
3
- metadata.gz: 2df520b8812cc17063343dec89c82fd4ef94feb5
4
- data.tar.gz: 3ef7f4309989802c211aa91f234547c69ecc654a
2
+ SHA256:
3
+ metadata.gz: e48d7a484f586f984a1ddd7bda0bd93680fd4419109eee75de349d0015709b62
4
+ data.tar.gz: 61fa02170bf32d34d2044f4a9275f0b5e9f0738dc77dddb2651f80016e9dc24d
5
5
  SHA512:
6
- metadata.gz: 9c752120deaf778e7cf356b79beec8f2b471de4c3356993bd476239c25c23e7e1dbb540c5c2e39c37627aa6958c0306f209a97176ec038bc07767e9f5d01a708
7
- data.tar.gz: 03f7fb48f8b91acd2e37260c4b6cfde7e18b4c2125ab4c2f2db56577c281f33bb4fc77a325ede3edb4a1a3e312afa37f85c4a69fb204b1d89cd96e763853e7b3
6
+ metadata.gz: 46dc861c18751412b0da582ed8bb105d9d91926d81bdd2ed357317b800a3171fc8279c65bfb4387d998ec51568fe595efcfce5c7ccc07072950647d95089146b
7
+ data.tar.gz: 8d09fa861bb32b16ce06e66d62b967d0b970d7f69410c1fba8eb83df6f496bb2bdfd75c886188b614b1a7537ecf263c632a1233ce5901f18daebf8aaf5bb66cd
@@ -1,9 +1,9 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.9
4
- - 2.3.6
5
- - 2.4.3
6
- - 2.5.0
3
+ - 2.2.10
4
+ - 2.3.7
5
+ - 2.4.4
6
+ - 2.5.1
7
7
  - ruby-head
8
8
 
9
9
  sudo: false
@@ -1,6 +1,10 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [0.3.0] 2018-06-15
5
+ ### Added
6
+ - `Symbiont::Isolator` - proc object isolation layer for delayed invocations;
7
+
4
8
  ## [0.2.0] 2018-04-22
5
9
  ### Added
6
10
  - Logo ^_^ (special thanks to **Viktoria Karaulova**)
data/README.md CHANGED
@@ -55,6 +55,7 @@ require 'symbiont'
55
55
  - [Mixing a module with default delegation direction](#mixing-a-module-with-default-delegation-direction)
56
56
  - [Mixing a module with certain delegation direction](#mixing-a-module-with-certain-delegation-direction)
57
57
  - [Multiple inner contexts](#multiple-inner-contexts)
58
+ - [Isolator - proc object isolation layer for delayed invocations](#isolator---proc-object-isolation-layer-for-delayed-invocations)
58
59
 
59
60
  # Problems and motivaiton
60
61
 
@@ -390,6 +391,34 @@ Symbiont::Executor.public_method(:data, object_a, object_b, &closure).call # =>
390
391
  Symbiont::Executor.public_method(:info, object_a, object_b, &closure).call # => "object_info"
391
392
  ```
392
393
 
394
+ ## Isolator - proc object isolation layer for delayed invocations
395
+
396
+ `Symbiont::Isolator` is a special object that wraps your proc object from any place and provides
397
+ an ability to invoke this proc object lazily inside an any series of contexts.
398
+ All `Symbiont::Executor` features are supported (by the way, `Symbiont::Executor`
399
+ uses `Symbiont::Isolator` under the hood).
400
+
401
+ ```ruby
402
+ # Usage:
403
+
404
+ # with default direction (Symbiont::IOK)
405
+ isolator = Symbiont::Isolator.new { call_any_method }
406
+
407
+ # with custom direction
408
+ isolator = Symbiont::Isolator.new(default_direction: Symbiont::KIO) { call_any_method }
409
+
410
+ # invocation
411
+ isolator.evaluate(object_a, object_b) # use default direction defined on instantiation
412
+ isolator.evaluate(object_a, object_b, direction: Symbiont::KOI) # use custom direction
413
+ # same for #.evaluate_private
414
+
415
+ # getting a method object
416
+ isolator.public_method(:call_any_method, object_a, object_b) # use default direction defined on instantiation
417
+ isolator.public_method(:call_any_method, object_a, object_b, direction: Symbiont::KIO) # use custom direction
418
+ isolator.private_method(...)
419
+ # same for #.private_method
420
+ ```
421
+
393
422
  # Contributing
394
423
 
395
424
  - Fork it ( https://github.com/0exp/symbiont-ruby/fork )
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'bundler/setup'
4
- require 'symbiont/ruby'
4
+ require 'symbiont'
5
5
 
6
6
  require 'pry'
7
7
  Pry.start
@@ -9,6 +9,7 @@ module Symbiont
9
9
  require_relative 'symbiont/trigger'
10
10
  require_relative 'symbiont/public_trigger'
11
11
  require_relative 'symbiont/private_trigger'
12
+ require_relative 'symbiont/isolator'
12
13
  require_relative 'symbiont/executor'
13
14
  require_relative 'symbiont/context'
14
15
 
@@ -32,7 +32,8 @@ module Symbiont
32
32
  # @api public
33
33
  # @since 0.1.0
34
34
  def evaluate(*required_contexts, context_direction: Trigger::IOK, &closure)
35
- public_trigger(*required_contexts, context_direction: context_direction, &closure).__evaluate__
35
+ Isolator.new(default_direction: context_direction, &closure)
36
+ .evaluate(*required_contexts)
36
37
  end
37
38
 
38
39
  # Starts execution of a proc object in the context of the passed object with the selected
@@ -59,63 +60,8 @@ module Symbiont
59
60
  # @api public
60
61
  # @since 0.1.0
61
62
  def evaluate_private(*required_contexts, context_direction: Trigger::IOK, &closure)
62
- private_trigger(*required_contexts, context_direction: context_direction, &closure).__evaluate__
63
- end
64
-
65
- # Factory method that instantiates a public trigger with the desired execution context,
66
- # the direction of method dispatching and the closure that needs to be performed.
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.
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
80
- # @param closure [Proc]
81
- # Proc object that will be evaluated in many contexts: initial, outer and kernel.
82
- # @return [Symbiont::PublicTrigger]
83
- #
84
- # @see Symbiont::PublicTrigger
85
- # @see Symbiont::Trigger
86
- #
87
- # @api public
88
- # @since 0.1.0
89
- def public_trigger(*required_contexts, context_direction: Trigger::IOK, &closure)
90
- PublicTrigger.new(*required_contexts, context_direction: context_direction, &closure)
91
- end
92
-
93
- # Factory method that instantiates a private trigger with the desired execution context,
94
- # the direction of method dispatching and the closure that needs to be performed.
95
- #
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.
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
108
- # @param closure [Proc]
109
- # Proc object that will be evaluated in many contexts: initial, outer and kernel.
110
- # @return [Symbiont::PrivateTrigger]
111
- #
112
- # @see Symbiont::PrivateTrigger
113
- # @see Symbiont::Trigger
114
- #
115
- # @api public
116
- # @since 0.1.0
117
- def private_trigger(*required_contexts, context_direction: Trigger::IOK, &closure)
118
- PrivateTrigger.new(*required_contexts, context_direction: context_direction, &closure)
63
+ Isolator.new(default_direction: context_direction, &closure)
64
+ .evaluate_private(*required_contexts)
119
65
  end
120
66
 
121
67
  # Gets the method object taken from the context that can respond to it.
@@ -142,7 +88,8 @@ module Symbiont
142
88
  # @api public
143
89
  # @since 0.1.0
144
90
  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
+ Isolator.new(default_direction: context_direction, &closure)
92
+ .public_method(method_name, *required_contexts)
146
93
  end
147
94
 
148
95
  # Gets the method object taken from the context that can respond to it.
@@ -169,7 +116,8 @@ module Symbiont
169
116
  # @api public
170
117
  # @since 0.1.0
171
118
  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)
119
+ Isolator.new(default_direction: context_direction, &closure)
120
+ .private_method(method_name, *required_contexts)
173
121
  end
174
122
  end
175
123
  end
@@ -0,0 +1,185 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Symbiont
4
+ # Special object that wraps your proc object from any place and provides
5
+ # an ability to invoke this proc object lazily inside an any series of contexts.
6
+ #
7
+ # @api public
8
+ # @since 0.3.0
9
+ class Isolator
10
+ # Is raised when closure is not provided.
11
+ #
12
+ # @see #initialize
13
+ #
14
+ # @api public
15
+ # @since 0.3.0
16
+ UnprovidedClosureAttributeError = Class.new(ArgumentError)
17
+
18
+ # Proc object that will be evaluated in many contexts: initial, outer and kernel.
19
+ # Will be used as an outer-context for the method resolution.
20
+ #
21
+ # @return [Proc]
22
+ #
23
+ # @api public
24
+ # @since 0.3.0
25
+ attr_reader :closure
26
+
27
+ # An array of symbols that represents the direction of contexts. Used by default.
28
+ #
29
+ # @return [Array<Symbol>]
30
+ #
31
+ # @api public
32
+ # @since 0.3.0
33
+ attr_reader :default_direction
34
+
35
+ # Instantiates isolator object with corresponding default direction and closure.
36
+ #
37
+ # @option default_direction [Array<Symbol>]
38
+ # An array of symbols that represents the direction of contexts which is used as default
39
+ # context direction. Symbiont::Trigger::IOK is chosen by default.
40
+ # @param closure [Proc]
41
+ # Proc object that will be evaluated in many contexts: initial, outer and kernel.
42
+ # Will be used as an outer-context for the method resolution.
43
+ #
44
+ # @api public
45
+ # @since 0.3.0
46
+ def initialize(default_direction: Trigger::IOK, &closure)
47
+ raise UnprovidedClosureAttributeError, 'You should provide a closure' unless block_given?
48
+
49
+ @default_direction = default_direction
50
+ @closure = closure
51
+ end
52
+
53
+ # Starts execution of a proc object in the context of the passed object with the selected
54
+ # direction of method dispatching. Delegates execution to a public trigger.
55
+ #
56
+ # @param required_contexts [Array<Object>]
57
+ # A set of objects that should be used as the main context series for method resolving
58
+ # algorithm.
59
+ # @param direction [Array<Symbol>]
60
+ # An array of symbols that represents the direction of contexts.
61
+ # @return [void]
62
+ #
63
+ # @see Symbiont::Trigger#__evaluate__
64
+ # @see Symbiont::PublicTrigger
65
+ #
66
+ # @api public
67
+ # @since 0.3.0
68
+ def evaluate(*required_contexts, direction: default_direction)
69
+ public_trigger(*required_contexts, direction: direction).__evaluate__
70
+ end
71
+
72
+ # Starts execution of a proc object in the context of the passed object with the selected
73
+ # direction of method dispatching. Delegates execution to a private trigger.
74
+ #
75
+ # @param required_contexts [Array<Object>]
76
+ # A set of objects that should be used as the main context series for method resolving
77
+ # algorithm.
78
+ # @param direction [Array<Symbol>]
79
+ # An array of symbols that represents the direction of contexts.
80
+ # @return [void]
81
+ #
82
+ # @see Symbiont::Trigger#__evaluate__
83
+ # @see Symbiont::PrivateTrigger
84
+ #
85
+ # @api public
86
+ # @since 0.3.0
87
+ def evaluate_private(*required_contexts, direction: default_direction)
88
+ private_trigger(*required_contexts, direction: direction).__evaluate__
89
+ end
90
+
91
+ # Gets the method object taken from the context that can respond to it.
92
+ # Considers only public methods.
93
+ #
94
+ # @param method_name [Symbol,String] A name of required method.
95
+ # @param required_contexts [Array<Object>]
96
+ # A set of objects that should be used as the main context series for method resolving
97
+ # algorithm.
98
+ # @param direction [Array<Symbol>]
99
+ # An array of symbols that represents the direction of contexts.
100
+ # @return [Method]
101
+ #
102
+ # @see Symbiont::PublicTrigger
103
+ # @see Symbiont::Trigger#method
104
+ #
105
+ # @api public
106
+ # @since 0.3.0
107
+ def public_method(method_name, *required_contexts, direction: default_direction)
108
+ public_trigger(*required_contexts, direction: direction).method(method_name)
109
+ end
110
+
111
+ # Gets the method object taken from the context that can respond to it.
112
+ # Considers private methods and public methods.
113
+ #
114
+ # @param method_name [Symbol,String] A name of required method.
115
+ # @param required_contexts [Array<Object>]
116
+ # A set of objects that should be used as the main context series for method resolving
117
+ # algorithm.
118
+ # @param direction [Array<Symbol>]
119
+ # An array of symbols that represents the direction of contexts.
120
+ # @return [Method]
121
+ #
122
+ # @see Symbiont::PrivateTrigger
123
+ # @see Symbiont::Trigger#method
124
+ #
125
+ # @api public
126
+ # @since 0.3.0
127
+ def private_method(method_name, *required_contexts, direction: default_direction)
128
+ private_trigger(*required_contexts, direction: direction).method(method_name)
129
+ end
130
+
131
+ private
132
+
133
+ # Factory method that instantiates a public trigger with the desired execution context,
134
+ # the direction of method dispatching and the closure that needs to be performed.
135
+ #
136
+ # @param required_contexts [Array<Object>]
137
+ # A set of objects that should be used as the main context series for method resolving
138
+ # algorithm.
139
+ # @param direction [Array<Symbol>]
140
+ # An array of symbols that represents the direction of contexts. Possible values:
141
+ #
142
+ # - Symbiont::IOK
143
+ # - Symbiont::OIK
144
+ # - Symbiont::OKI
145
+ # - Symbiont::IKO
146
+ # - Symbiont::KOI
147
+ # - Symbiont::KIO
148
+ # @return [Symbiont::PublicTrigger]
149
+ #
150
+ # @see Symbiont::PublicTrigger
151
+ # @see Symbiont::Trigger
152
+ #
153
+ # @api private
154
+ # @since 0.3.0
155
+ def public_trigger(*required_contexts, direction: default_direction)
156
+ PublicTrigger.new(*required_contexts, context_direction: direction, &closure)
157
+ end
158
+
159
+ # Factory method that instantiates a private trigger with the desired execution context,
160
+ # the direction of method dispatching and the closure that needs to be performed.
161
+ #
162
+ # @param required_contexts [Array<Object>]
163
+ # A set of objects that should be used as the main context series for method resolving
164
+ # algorithm.
165
+ # @param direction [Array<Symbol>]
166
+ # An array of symbols that represents the direction of contexts. Possible values:
167
+ #
168
+ # - Symbiont::IOK
169
+ # - Symbiont::OIK
170
+ # - Symbiont::OKI
171
+ # - Symbiont::IKO
172
+ # - Symbiont::KOI
173
+ # - Symbiont::KIO
174
+ # @return [Symbiont::PrivateTrigger]
175
+ #
176
+ # @see Symbiont::PrivateTrigger
177
+ # @see Symbiont::Trigger
178
+ #
179
+ # @api private
180
+ # @since 0.3.0
181
+ def private_trigger(*required_contexts, direction: default_direction)
182
+ PrivateTrigger.new(*required_contexts, context_direction: direction, &closure)
183
+ end
184
+ end
185
+ end
@@ -153,9 +153,11 @@ class Symbiont::Trigger < BasicObject
153
153
  # @api private
154
154
  # @since 0.1.0
155
155
  def initialize(*initial_contexts, context_direction: IOK, &closure)
156
+ # :nocov:
156
157
  unless ::Kernel.block_given?
157
158
  ::Kernel.raise(UnprovidedClosureAttributeError, 'block attribute should be provided')
158
159
  end
160
+ # :nocov:
159
161
 
160
162
  # rubocop:disable Layout/SpaceAroundKeyword
161
163
  unless(context_direction == IOK || context_direction == OIK || context_direction == OKI ||
@@ -230,7 +232,7 @@ class Symbiont::Trigger < BasicObject
230
232
  #
231
233
  # @api private
232
234
  # @since 0.1.0
233
- def method_missing(method_name, *arguments, &block) # rubocop:disable Style/MethodMissing
235
+ def method_missing(method_name, *arguments, &block) # rubocop:disable Style/MethodMissingSuper
234
236
  __actual_context__(method_name).send(method_name, *arguments, &block)
235
237
  end
236
238
 
@@ -5,5 +5,5 @@ module Symbiont
5
5
  #
6
6
  # @api public
7
7
  # @since 0.1.0
8
- VERSION = '0.2.0'
8
+ VERSION = '0.3.0'
9
9
  end
@@ -29,8 +29,8 @@ Gem::Specification.new do |spec|
29
29
  end
30
30
 
31
31
  spec.add_development_dependency 'rspec', '~> 3.7'
32
- spec.add_development_dependency 'rubocop', '~> 0.53'
33
- spec.add_development_dependency 'rubocop-rspec', '~> 1.24'
32
+ spec.add_development_dependency 'rubocop', '~> 0.57'
33
+ spec.add_development_dependency 'rubocop-rspec', '~> 1.26'
34
34
  spec.add_development_dependency 'simplecov', '~> 0.15'
35
35
  spec.add_development_dependency 'simplecov-json', '~> 0.2'
36
36
  spec.add_development_dependency 'coveralls', '~> 0.7'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: symbiont-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rustam Ibragimov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-21 00:00:00.000000000 Z
11
+ date: 2018-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -30,28 +30,28 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.53'
33
+ version: '0.57'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.53'
40
+ version: '0.57'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rubocop-rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.24'
47
+ version: '1.26'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.24'
54
+ version: '1.26'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: simplecov
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -161,7 +161,6 @@ extensions: []
161
161
  extra_rdoc_files: []
162
162
  files:
163
163
  - ".gitignore"
164
- - ".hound.yml"
165
164
  - ".rspec"
166
165
  - ".rubocop.yml"
167
166
  - ".travis.yml"
@@ -176,6 +175,7 @@ files:
176
175
  - lib/symbiont.rb
177
176
  - lib/symbiont/context.rb
178
177
  - lib/symbiont/executor.rb
178
+ - lib/symbiont/isolator.rb
179
179
  - lib/symbiont/private_trigger.rb
180
180
  - lib/symbiont/public_trigger.rb
181
181
  - lib/symbiont/trigger.rb
@@ -235,7 +235,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
235
235
  version: '0'
236
236
  requirements: []
237
237
  rubyforge_project:
238
- rubygems_version: 2.6.14
238
+ rubygems_version: 2.7.6
239
239
  signing_key:
240
240
  specification_version: 4
241
241
  summary: Evaluate proc-objects in many contexts simultaneously
data/.hound.yml DELETED
@@ -1,2 +0,0 @@
1
- ruby:
2
- config_file: .rubocop.yml