smart_engine 0.3.0 → 0.8.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 +5 -1
- data/.travis.yml +6 -5
- data/CHANGELOG.md +22 -1
- data/Gemfile.lock +60 -42
- data/README.md +116 -5
- data/Rakefile +2 -1
- data/lib/smart_core/engine.rb +4 -0
- data/lib/smart_core/engine/atom.rb +43 -0
- data/lib/smart_core/engine/frozener.rb +57 -0
- data/lib/smart_core/engine/lock.rb +22 -0
- data/lib/smart_core/engine/rescue_ext.rb +44 -0
- data/lib/smart_core/engine/version.rb +2 -2
- data/lib/smart_core/errors.rb +4 -0
- data/smart_engine.gemspec +4 -4
- metadata +13 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 228fbd594308ecee71718fe059d6d8bf57f8e79f33b0607ca4b771fc498a0ac4
|
|
4
|
+
data.tar.gz: 809d274f771a7de133a1bc8986448ffca67bcefa2f0fd5f3a5d39cf730c448fa
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 29eb3e3f8e005af66036b33c3bdb7260d8da6054dd63177b50d7a1bb0cd6b4a6ba39a61c03a77420a9d2867fbc4424a7a2718e535c0dd6afefa4f699c6c33beb
|
|
7
|
+
data.tar.gz: 70f57850d865a3dcbfbc083f444c30a86bd24745501e1816efff41db049c294ae5844f2c2bf6856316137a20d7be7b00c32964a852f576245ab0f378d40bb06e
|
data/.rubocop.yml
CHANGED
|
@@ -5,7 +5,7 @@ inherit_gem:
|
|
|
5
5
|
- lib/rubocop.rspec.yml
|
|
6
6
|
|
|
7
7
|
AllCops:
|
|
8
|
-
TargetRubyVersion: 2.
|
|
8
|
+
TargetRubyVersion: 2.7.1
|
|
9
9
|
Include:
|
|
10
10
|
- lib/**/*.rb
|
|
11
11
|
- spec/**/*.rb
|
|
@@ -13,3 +13,7 @@ AllCops:
|
|
|
13
13
|
- Rakefile
|
|
14
14
|
- smart_engine.gemspec
|
|
15
15
|
- bin/console
|
|
16
|
+
|
|
17
|
+
# NOTE: for better representativeness of test examples
|
|
18
|
+
RSpec/DescribedClass:
|
|
19
|
+
Enabled: false
|
data/.travis.yml
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
---
|
|
2
2
|
language: ruby
|
|
3
3
|
cache: bundler
|
|
4
|
-
before_install: gem install bundler
|
|
4
|
+
before_install: gem install bundler
|
|
5
5
|
os: linux
|
|
6
|
+
dist: xenial
|
|
6
7
|
script:
|
|
7
8
|
- bundle exec rake rubocop
|
|
8
9
|
- bundle exec rake rspec
|
|
9
10
|
jobs:
|
|
10
11
|
fast_finish: true
|
|
11
12
|
include:
|
|
12
|
-
- rvm: 2.4.
|
|
13
|
-
- rvm: 2.5.
|
|
14
|
-
- rvm: 2.6.
|
|
15
|
-
- rvm: 2.7.
|
|
13
|
+
- rvm: 2.4.10
|
|
14
|
+
- rvm: 2.5.8
|
|
15
|
+
- rvm: 2.6.6
|
|
16
|
+
- rvm: 2.7.1
|
|
16
17
|
- rvm: ruby-head
|
|
17
18
|
- rvm: jruby-head
|
|
18
19
|
allow_failures:
|
data/CHANGELOG.md
CHANGED
|
@@ -1,7 +1,28 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
All notable changes to this project will be documented in this file.
|
|
3
3
|
|
|
4
|
-
## [0.
|
|
4
|
+
## [0.8.0] - 2020-07-25
|
|
5
|
+
### Added
|
|
6
|
+
- Any object frozener (`SmartCore::Engine::Frozener`, `SmartCore::Engine::Frozener::Mixin`);
|
|
7
|
+
|
|
8
|
+
## [0.7.0] - 2020-07-03
|
|
9
|
+
### Added
|
|
10
|
+
- Atomic threadsafe value container (`SmartCore::Engine::Atom`);
|
|
11
|
+
|
|
12
|
+
## [0.6.0] - 2020-05-03
|
|
13
|
+
### Added
|
|
14
|
+
- Inline rescue pipe (`SmartCore::Engine::RescueExt.inline_rescue_pipe`);
|
|
15
|
+
- Actualized development dependencies and test environment;
|
|
16
|
+
|
|
17
|
+
## [0.5.0] - 2020-01-22
|
|
18
|
+
### Added
|
|
19
|
+
- Global error type `SmartCore::TypeError` inherited from `::TypeError`;
|
|
20
|
+
|
|
21
|
+
## [0.4.0] - 2020-01-19
|
|
22
|
+
### Added
|
|
23
|
+
- `SmartCore::Engine::Lock` - simple reentrant-based locking primitive;
|
|
24
|
+
|
|
25
|
+
## [0.3.0] - 2020-01-17
|
|
5
26
|
### Added
|
|
6
27
|
- Global error type `SmartCore::NameError` inherited from `::NameError`;
|
|
7
28
|
|
data/Gemfile.lock
CHANGED
|
@@ -1,81 +1,99 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
smart_engine (0.
|
|
4
|
+
smart_engine (0.7.0)
|
|
5
5
|
|
|
6
6
|
GEM
|
|
7
7
|
remote: https://rubygems.org/
|
|
8
8
|
specs:
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
activesupport (6.0.3.2)
|
|
10
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
11
|
+
i18n (>= 0.7, < 2)
|
|
12
|
+
minitest (~> 5.1)
|
|
13
|
+
tzinfo (~> 1.1)
|
|
14
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
|
15
|
+
armitage-rubocop (0.87.1)
|
|
16
|
+
rubocop (= 0.87.1)
|
|
17
|
+
rubocop-performance (= 1.7.0)
|
|
18
|
+
rubocop-rails (= 2.6.0)
|
|
19
|
+
rubocop-rake (= 0.5.1)
|
|
20
|
+
rubocop-rspec (= 1.41.0)
|
|
21
|
+
ast (2.4.1)
|
|
16
22
|
coderay (1.1.2)
|
|
17
|
-
|
|
23
|
+
concurrent-ruby (1.1.6)
|
|
24
|
+
diff-lcs (1.4.4)
|
|
18
25
|
docile (1.3.2)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
method_source (0.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
i18n (1.8.3)
|
|
27
|
+
concurrent-ruby (~> 1.0)
|
|
28
|
+
method_source (1.0.0)
|
|
29
|
+
minitest (5.14.1)
|
|
30
|
+
parallel (1.19.2)
|
|
31
|
+
parser (2.7.1.4)
|
|
32
|
+
ast (~> 2.4.1)
|
|
33
|
+
pry (0.13.1)
|
|
34
|
+
coderay (~> 1.1)
|
|
35
|
+
method_source (~> 1.0)
|
|
36
|
+
rack (2.2.3)
|
|
29
37
|
rainbow (3.0.0)
|
|
30
38
|
rake (13.0.1)
|
|
39
|
+
regexp_parser (1.7.1)
|
|
40
|
+
rexml (3.2.4)
|
|
31
41
|
rspec (3.9.0)
|
|
32
42
|
rspec-core (~> 3.9.0)
|
|
33
43
|
rspec-expectations (~> 3.9.0)
|
|
34
44
|
rspec-mocks (~> 3.9.0)
|
|
35
|
-
rspec-core (3.9.
|
|
36
|
-
rspec-support (~> 3.9.
|
|
37
|
-
rspec-expectations (3.9.
|
|
45
|
+
rspec-core (3.9.2)
|
|
46
|
+
rspec-support (~> 3.9.3)
|
|
47
|
+
rspec-expectations (3.9.2)
|
|
38
48
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
39
49
|
rspec-support (~> 3.9.0)
|
|
40
50
|
rspec-mocks (3.9.1)
|
|
41
51
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
42
52
|
rspec-support (~> 3.9.0)
|
|
43
|
-
rspec-support (3.9.
|
|
44
|
-
rubocop (0.
|
|
45
|
-
jaro_winkler (~> 1.5.1)
|
|
53
|
+
rspec-support (3.9.3)
|
|
54
|
+
rubocop (0.87.1)
|
|
46
55
|
parallel (~> 1.10)
|
|
47
|
-
parser (>= 2.7.
|
|
56
|
+
parser (>= 2.7.1.1)
|
|
48
57
|
rainbow (>= 2.2.2, < 4.0)
|
|
58
|
+
regexp_parser (>= 1.7)
|
|
59
|
+
rexml
|
|
60
|
+
rubocop-ast (>= 0.1.0, < 1.0)
|
|
49
61
|
ruby-progressbar (~> 1.7)
|
|
50
|
-
unicode-display_width (>= 1.4.0, <
|
|
51
|
-
rubocop-
|
|
52
|
-
|
|
53
|
-
rubocop-
|
|
62
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
|
63
|
+
rubocop-ast (0.1.0)
|
|
64
|
+
parser (>= 2.7.0.1)
|
|
65
|
+
rubocop-performance (1.7.0)
|
|
66
|
+
rubocop (>= 0.82.0)
|
|
67
|
+
rubocop-rails (2.6.0)
|
|
68
|
+
activesupport (>= 4.2.0)
|
|
54
69
|
rack (>= 1.1)
|
|
55
|
-
rubocop (>= 0.
|
|
56
|
-
rubocop-rake (0.5.
|
|
70
|
+
rubocop (>= 0.82.0)
|
|
71
|
+
rubocop-rake (0.5.1)
|
|
57
72
|
rubocop
|
|
58
|
-
rubocop-rspec (1.
|
|
73
|
+
rubocop-rspec (1.41.0)
|
|
59
74
|
rubocop (>= 0.68.1)
|
|
60
75
|
ruby-progressbar (1.10.1)
|
|
61
|
-
simplecov (0.
|
|
76
|
+
simplecov (0.18.5)
|
|
62
77
|
docile (~> 1.1)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
78
|
+
simplecov-html (~> 0.11)
|
|
79
|
+
simplecov-html (0.12.2)
|
|
80
|
+
thread_safe (0.3.6)
|
|
81
|
+
tzinfo (1.2.7)
|
|
82
|
+
thread_safe (~> 0.1)
|
|
83
|
+
unicode-display_width (1.7.0)
|
|
84
|
+
zeitwerk (2.3.1)
|
|
67
85
|
|
|
68
86
|
PLATFORMS
|
|
69
87
|
ruby
|
|
70
88
|
|
|
71
89
|
DEPENDENCIES
|
|
72
|
-
armitage-rubocop (~> 0.
|
|
90
|
+
armitage-rubocop (~> 0.87)
|
|
73
91
|
bundler (~> 2.1)
|
|
74
|
-
pry (~> 0.
|
|
92
|
+
pry (~> 0.13)
|
|
75
93
|
rake (~> 13.0)
|
|
76
94
|
rspec (~> 3.9)
|
|
77
|
-
simplecov (~> 0.
|
|
95
|
+
simplecov (~> 0.18)
|
|
78
96
|
smart_engine!
|
|
79
97
|
|
|
80
98
|
BUNDLED WITH
|
|
81
|
-
2.1.
|
|
99
|
+
2.1.4
|
data/README.md
CHANGED
|
@@ -22,11 +22,122 @@ require 'smart_core'
|
|
|
22
22
|
|
|
23
23
|
## Technologies
|
|
24
24
|
|
|
25
|
-
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
- [Global set of error types](#global-set-of-error-types)
|
|
26
|
+
- [Simple reentrant lock](#simple-reentrant-lock)
|
|
27
|
+
- [Atomic thread-safe value container](#atomic-thread-safe-value-container)
|
|
28
|
+
- [Any Object Frozener](#any-object-frozener)
|
|
29
|
+
- [Inline rescue pipe](#inline-rescue-pipe)
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
### Global set of error types
|
|
34
|
+
|
|
35
|
+
- `SmartCore::Error` (inherited from `::StandardError`);
|
|
36
|
+
- `SmartCore::ArgumentError` (inherited from `::ArgumentError`);
|
|
37
|
+
- `SmartCore::FrozenError` (inherited from `::FrozenError`);
|
|
38
|
+
- `SmartCore::NameError` (inherited from `::NameError`);
|
|
39
|
+
- `SmartCore::TypeError` (inherited from `::TypeError`);
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
### Simple reentrant lock
|
|
44
|
+
|
|
45
|
+
```ruby
|
|
46
|
+
lock = SmartCore::Engine::Lock.new
|
|
47
|
+
lock.synchronize { your_code }
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
### Atomic thread-safe value container
|
|
53
|
+
|
|
54
|
+
```ruby
|
|
55
|
+
atom = SmartCore::Engine::Atom.new # initial value - nil
|
|
56
|
+
atom.value # => nil
|
|
57
|
+
# --- or ---
|
|
58
|
+
atom = SmartCore::Engine::Atom.new(7) # initial value - 7
|
|
59
|
+
atom.value # => 7
|
|
60
|
+
|
|
61
|
+
# set new value (thread-safely)
|
|
62
|
+
atom.swap { |original_value| original_value * 2 }
|
|
63
|
+
atom.value # => 14
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
### Any Object Frozener
|
|
69
|
+
|
|
70
|
+
- works with any type of ruby objects (event with `BasicObject`);
|
|
71
|
+
|
|
72
|
+
```ruby
|
|
73
|
+
# as a singleton
|
|
74
|
+
|
|
75
|
+
object = BasicObject.new
|
|
76
|
+
SmartCore::Engine::Frozener.frozen?(object) # => false
|
|
77
|
+
|
|
78
|
+
SmartCore::Engine::Frozener.freeze(object)
|
|
79
|
+
SmartCore::Engine::Frozener.frozen?(object) # => true
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
```ruby
|
|
83
|
+
# as a mixin
|
|
84
|
+
|
|
85
|
+
class EmptyObject < BasicObject
|
|
86
|
+
include SmartCore::Engine::Frozener::Mixin
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
object = EmptyObject.new
|
|
90
|
+
|
|
91
|
+
object.frozen? # => false
|
|
92
|
+
object.freeze
|
|
93
|
+
object.frozen? # => true
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
### Inline rescue pipe
|
|
99
|
+
|
|
100
|
+
- works with an array of proc objects;
|
|
101
|
+
- returns the result of the first non-failed proc;
|
|
102
|
+
- provides an error interception interface (a block argument);
|
|
103
|
+
- fails with the last failed proc exception (if all procs were failed and interceptor was not passed);
|
|
104
|
+
|
|
105
|
+
#### Return the result of the first non-failed proc
|
|
106
|
+
|
|
107
|
+
```ruby
|
|
108
|
+
SmartCore::Engine::RescueExt.inline_rescue_pipe(
|
|
109
|
+
-> { raise },
|
|
110
|
+
-> { raise },
|
|
111
|
+
-> { 123 },
|
|
112
|
+
-> { 567 },
|
|
113
|
+
-> { raise },
|
|
114
|
+
)
|
|
115
|
+
# => output: 123
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
#### Fail with the last failed proc exception
|
|
119
|
+
|
|
120
|
+
```ruby
|
|
121
|
+
SmartCore::Engine::RescueExt.inline_rescue_pipe(
|
|
122
|
+
-> { raise(::ArgumentError) },
|
|
123
|
+
-> { raise(::TypeError) },
|
|
124
|
+
-> { raise(::ZeroDivisionError) }
|
|
125
|
+
)
|
|
126
|
+
# => fails with ZeroDivisionError
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
#### Error interception
|
|
130
|
+
|
|
131
|
+
```ruby
|
|
132
|
+
SmartCore::Engine::RescueExt.inline_rescue_pipe(
|
|
133
|
+
-> { raise(::ArgumentError) },
|
|
134
|
+
-> { raise(::TypeError) },
|
|
135
|
+
-> { raise(::ZeroDivisionError, 'Intercepted exception') }
|
|
136
|
+
) do |error|
|
|
137
|
+
error.message
|
|
138
|
+
end
|
|
139
|
+
# => output: "Intercepted exception"
|
|
140
|
+
```
|
|
30
141
|
|
|
31
142
|
---
|
|
32
143
|
|
data/Rakefile
CHANGED
|
@@ -4,6 +4,7 @@ require 'bundler/gem_tasks'
|
|
|
4
4
|
require 'rspec/core/rake_task'
|
|
5
5
|
require 'rubocop'
|
|
6
6
|
require 'rubocop/rake_task'
|
|
7
|
+
require 'rubocop-rails'
|
|
7
8
|
require 'rubocop-performance'
|
|
8
9
|
require 'rubocop-rspec'
|
|
9
10
|
require 'rubocop-rake'
|
|
@@ -11,8 +12,8 @@ require 'rubocop-rake'
|
|
|
11
12
|
RuboCop::RakeTask.new(:rubocop) do |t|
|
|
12
13
|
config_path = File.expand_path(File.join('.rubocop.yml'), __dir__)
|
|
13
14
|
t.options = ['--config', config_path]
|
|
14
|
-
t.requires << 'rubocop-performance'
|
|
15
15
|
t.requires << 'rubocop-rspec'
|
|
16
|
+
t.requires << 'rubocop-performance'
|
|
16
17
|
t.requires << 'rubocop-rake'
|
|
17
18
|
end
|
|
18
19
|
|
data/lib/smart_core/engine.rb
CHANGED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# @api public
|
|
4
|
+
# @since 0.7.0
|
|
5
|
+
class SmartCore::Engine::Atom
|
|
6
|
+
# @param initial_value [Any]
|
|
7
|
+
# @return [void]
|
|
8
|
+
#
|
|
9
|
+
# @api private
|
|
10
|
+
# @since 0.7.0
|
|
11
|
+
def initialize(initial_value = nil)
|
|
12
|
+
@value = initial_value
|
|
13
|
+
@barrier = SmartCore::Engine::Lock.new
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# @return [Any]
|
|
17
|
+
#
|
|
18
|
+
# @api public
|
|
19
|
+
# @since 0.7.0
|
|
20
|
+
def value
|
|
21
|
+
with_barrier { @value }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# @param block [Block]
|
|
25
|
+
# @return [Any]
|
|
26
|
+
#
|
|
27
|
+
# @api public
|
|
28
|
+
# @since 0.7.0
|
|
29
|
+
def swap(&block)
|
|
30
|
+
with_barrier { @value = yield(@value) }
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
private
|
|
34
|
+
|
|
35
|
+
# @param block [Block]
|
|
36
|
+
# @return [Any]
|
|
37
|
+
#
|
|
38
|
+
# @api private
|
|
39
|
+
# @since 0.1.0
|
|
40
|
+
def with_barrier(&block)
|
|
41
|
+
@barrier.synchronize(&block)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# @api public
|
|
4
|
+
# @since 0.8.0
|
|
5
|
+
module SmartCore::Engine::Frozener
|
|
6
|
+
# @api public
|
|
7
|
+
# @since 0.8.0
|
|
8
|
+
module Mixin
|
|
9
|
+
# @return [self]
|
|
10
|
+
#
|
|
11
|
+
# @api public
|
|
12
|
+
# @since 0.8.0
|
|
13
|
+
def freeze
|
|
14
|
+
SmartCore::Engine::Frozener.freeze(self)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# @return [Boolean]
|
|
18
|
+
#
|
|
19
|
+
# @api public
|
|
20
|
+
# @since 0.8.0
|
|
21
|
+
def frozen?
|
|
22
|
+
SmartCore::Engine::Frozener.frozen?(self)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# @return [UnboundMethod]
|
|
27
|
+
#
|
|
28
|
+
# @api private
|
|
29
|
+
# @since 0.8.0
|
|
30
|
+
FROZENER = Object.new.method(:freeze).unbind.tap(&:freeze)
|
|
31
|
+
|
|
32
|
+
# @return [UnboundMethod]
|
|
33
|
+
#
|
|
34
|
+
# @api private
|
|
35
|
+
# @since 0.8.0
|
|
36
|
+
FROZEN_CHECK = Object.new.method(:frozen?).unbind.tap(&:freeze)
|
|
37
|
+
|
|
38
|
+
class << self
|
|
39
|
+
# @param object [Any]
|
|
40
|
+
# @return [object]
|
|
41
|
+
#
|
|
42
|
+
# @api public
|
|
43
|
+
# @since 0.8.0
|
|
44
|
+
def freeze(object)
|
|
45
|
+
FROZENER.bind_call(object)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# @param object [Any]
|
|
49
|
+
# @return [Boolean]
|
|
50
|
+
#
|
|
51
|
+
# @api public
|
|
52
|
+
# @since 0.8.0
|
|
53
|
+
def frozen?(object)
|
|
54
|
+
FROZEN_CHECK.bind_call(object)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# @api public
|
|
4
|
+
# @since 0.4.0
|
|
5
|
+
class SmartCore::Engine::Lock
|
|
6
|
+
# @return [void]
|
|
7
|
+
#
|
|
8
|
+
# @api public
|
|
9
|
+
# @since 0.4.0
|
|
10
|
+
def initialize
|
|
11
|
+
@lock = Mutex.new
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# @param block [Block]
|
|
15
|
+
# @return [Any]
|
|
16
|
+
#
|
|
17
|
+
# @api public
|
|
18
|
+
# @since 0.4.0
|
|
19
|
+
def synchronize(&block)
|
|
20
|
+
@lock.owned? ? yield : @lock.synchronize(&block)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# @api public
|
|
4
|
+
# @since 0.6.0
|
|
5
|
+
module SmartCore::Engine::RescueExt
|
|
6
|
+
# REASON:
|
|
7
|
+
# {module_funciton} is used to be able to include/extend any module/class
|
|
8
|
+
# and at the same time to use without any inclusion/extending logic as a service
|
|
9
|
+
|
|
10
|
+
module_function
|
|
11
|
+
|
|
12
|
+
# @param proks [Array<Proc>]
|
|
13
|
+
# @param error_interceptor [Block]
|
|
14
|
+
# @return [Any]
|
|
15
|
+
#
|
|
16
|
+
# @api public
|
|
17
|
+
# @since 0.6.0
|
|
18
|
+
# rubocop:disable Performance/RedundantBlockCall
|
|
19
|
+
def inline_rescue_pipe(*proks, &error_interceptor)
|
|
20
|
+
unless proks.all? { |prok| prok.is_a?(::Proc) }
|
|
21
|
+
raise(SmartCore::ArgumentError, 'Invalid proc object')
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
interceptable_bloks = proks.to_enum
|
|
25
|
+
pipe_invokation_result = nil
|
|
26
|
+
last_exception = nil
|
|
27
|
+
|
|
28
|
+
begin
|
|
29
|
+
while current_block = interceptable_bloks.next
|
|
30
|
+
begin
|
|
31
|
+
pipe_invokation_result = current_block.call
|
|
32
|
+
break
|
|
33
|
+
rescue => error
|
|
34
|
+
last_exception = error
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
pipe_invokation_result
|
|
39
|
+
rescue ::StopIteration
|
|
40
|
+
error_interceptor ? error_interceptor.call(last_exception) : raise(last_exception)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
# rubocop:enable Performance/RedundantBlockCall
|
|
44
|
+
end
|
data/lib/smart_core/errors.rb
CHANGED
data/smart_engine.gemspec
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
require_relative 'lib/smart_core/engine/version'
|
|
4
4
|
|
|
5
5
|
Gem::Specification.new do |spec|
|
|
6
|
-
spec.required_ruby_version = Gem::Requirement.new('>= 2.4.
|
|
6
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.4.10')
|
|
7
7
|
|
|
8
8
|
spec.name = 'smart_engine'
|
|
9
9
|
spec.version = SmartCore::Engine::VERSION
|
|
@@ -37,7 +37,7 @@ Gem::Specification.new do |spec|
|
|
|
37
37
|
spec.add_development_dependency 'bundler', '~> 2.1'
|
|
38
38
|
spec.add_development_dependency 'rake', '~> 13.0'
|
|
39
39
|
spec.add_development_dependency 'rspec', '~> 3.9'
|
|
40
|
-
spec.add_development_dependency 'armitage-rubocop', '~> 0.
|
|
41
|
-
spec.add_development_dependency 'simplecov', '~> 0.
|
|
42
|
-
spec.add_development_dependency 'pry', '~> 0.
|
|
40
|
+
spec.add_development_dependency 'armitage-rubocop', '~> 0.87'
|
|
41
|
+
spec.add_development_dependency 'simplecov', '~> 0.18'
|
|
42
|
+
spec.add_development_dependency 'pry', '~> 0.13'
|
|
43
43
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: smart_engine
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.8.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Rustam Ibragimov
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-
|
|
11
|
+
date: 2020-07-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -58,42 +58,42 @@ dependencies:
|
|
|
58
58
|
requirements:
|
|
59
59
|
- - "~>"
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: '0.
|
|
61
|
+
version: '0.87'
|
|
62
62
|
type: :development
|
|
63
63
|
prerelease: false
|
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
65
|
requirements:
|
|
66
66
|
- - "~>"
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: '0.
|
|
68
|
+
version: '0.87'
|
|
69
69
|
- !ruby/object:Gem::Dependency
|
|
70
70
|
name: simplecov
|
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
|
72
72
|
requirements:
|
|
73
73
|
- - "~>"
|
|
74
74
|
- !ruby/object:Gem::Version
|
|
75
|
-
version: '0.
|
|
75
|
+
version: '0.18'
|
|
76
76
|
type: :development
|
|
77
77
|
prerelease: false
|
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
|
79
79
|
requirements:
|
|
80
80
|
- - "~>"
|
|
81
81
|
- !ruby/object:Gem::Version
|
|
82
|
-
version: '0.
|
|
82
|
+
version: '0.18'
|
|
83
83
|
- !ruby/object:Gem::Dependency
|
|
84
84
|
name: pry
|
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
|
86
86
|
requirements:
|
|
87
87
|
- - "~>"
|
|
88
88
|
- !ruby/object:Gem::Version
|
|
89
|
-
version: '0.
|
|
89
|
+
version: '0.13'
|
|
90
90
|
type: :development
|
|
91
91
|
prerelease: false
|
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
|
93
93
|
requirements:
|
|
94
94
|
- - "~>"
|
|
95
95
|
- !ruby/object:Gem::Version
|
|
96
|
-
version: '0.
|
|
96
|
+
version: '0.13'
|
|
97
97
|
description: 'SmartCore Engine - a set of core functionality shared beetwen a series
|
|
98
98
|
of SmartCore gems.
|
|
99
99
|
|
|
@@ -119,6 +119,10 @@ files:
|
|
|
119
119
|
- bin/setup
|
|
120
120
|
- lib/smart_core.rb
|
|
121
121
|
- lib/smart_core/engine.rb
|
|
122
|
+
- lib/smart_core/engine/atom.rb
|
|
123
|
+
- lib/smart_core/engine/frozener.rb
|
|
124
|
+
- lib/smart_core/engine/lock.rb
|
|
125
|
+
- lib/smart_core/engine/rescue_ext.rb
|
|
122
126
|
- lib/smart_core/engine/version.rb
|
|
123
127
|
- lib/smart_core/errors.rb
|
|
124
128
|
- smart_engine.gemspec
|
|
@@ -137,7 +141,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
137
141
|
requirements:
|
|
138
142
|
- - ">="
|
|
139
143
|
- !ruby/object:Gem::Version
|
|
140
|
-
version: 2.4.
|
|
144
|
+
version: 2.4.10
|
|
141
145
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
146
|
requirements:
|
|
143
147
|
- - ">="
|