smart_engine 0.4.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +6 -1
- data/.travis.yml +5 -5
- data/CHANGELOG.md +34 -0
- data/Gemfile.lock +75 -54
- data/README.md +137 -2
- data/Rakefile +2 -1
- data/lib/smart_core.rb +1 -0
- data/lib/smart_core/engine.rb +3 -0
- data/lib/smart_core/engine/atom.rb +43 -0
- data/lib/smart_core/engine/ext.rb +7 -0
- data/lib/smart_core/engine/frozener.rb +60 -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/lib/smart_core/ext.rb +7 -0
- data/lib/smart_core/ext/basic_object_as_object.rb +42 -0
- data/smart_engine.gemspec +5 -5
- metadata +21 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72ab66864ab2ec1673cfcb6d48f0168560c9d7a843b2851f783f16d7bdb4fc63
|
4
|
+
data.tar.gz: 3c0c6273fbfce55343452efd6bcaa2726bdfaf8133a46b06ac69fb40762649cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8636209698ee6628cdc00af681b2400ffa6e7f4c479a3b2ae7a8cb9fdd14105a5c976791eadf541e56f1c41d719dd3d9c12adae2771468e3ba8c2be25e38a431
|
7
|
+
data.tar.gz: e886baa10d5c4d81b00b35e6c27b2ad60f2cd640acc8e57d22f9903596b475d53c9dce6c25b37f9abba11e1331e8b60705a87da15b5f0b904471d38529e9fdda
|
data/.rubocop.yml
CHANGED
@@ -5,7 +5,8 @@ inherit_gem:
|
|
5
5
|
- lib/rubocop.rspec.yml
|
6
6
|
|
7
7
|
AllCops:
|
8
|
-
TargetRubyVersion: 2.
|
8
|
+
TargetRubyVersion: 2.7.2
|
9
|
+
NewCops: enable
|
9
10
|
Include:
|
10
11
|
- lib/**/*.rb
|
11
12
|
- spec/**/*.rb
|
@@ -13,3 +14,7 @@ AllCops:
|
|
13
14
|
- Rakefile
|
14
15
|
- smart_engine.gemspec
|
15
16
|
- bin/console
|
17
|
+
|
18
|
+
# NOTE: for better representativeness of test examples
|
19
|
+
RSpec/DescribedClass:
|
20
|
+
Enabled: false
|
data/.travis.yml
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
---
|
2
2
|
language: ruby
|
3
3
|
cache: bundler
|
4
|
-
before_install: gem install bundler -v 2.1.2
|
5
4
|
os: linux
|
5
|
+
dist: xenial
|
6
|
+
before_install: gem install bundler
|
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.
|
13
|
-
- rvm: 2.
|
14
|
-
- rvm: 2.
|
15
|
-
- rvm: 2.7.0
|
13
|
+
- rvm: 2.5.8
|
14
|
+
- rvm: 2.6.6
|
15
|
+
- rvm: 2.7.2
|
16
16
|
- rvm: ruby-head
|
17
17
|
- rvm: jruby-head
|
18
18
|
allow_failures:
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,40 @@
|
|
1
1
|
# Changelog
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## [0.9.0] - 2020-12-20
|
5
|
+
### Added
|
6
|
+
- New type of utilities: *Extensions* (`SmartCore::Ext`);
|
7
|
+
- New extension: `SmartCore::Ext::BasicObjectAsObject` refinement:
|
8
|
+
- `using SmartCore::Ext::BasicObjectAsObject` provides native support for:
|
9
|
+
- `BasicObject#is_a?`;
|
10
|
+
- `BasicObject#kind_of?`;
|
11
|
+
- `BasicObject#freeze`;
|
12
|
+
- `BasicObject#frozen?`;
|
13
|
+
|
14
|
+
### Changed
|
15
|
+
- Updated development dependencies;
|
16
|
+
- Support for *Ruby@2.4* has ended;
|
17
|
+
|
18
|
+
### Fixed
|
19
|
+
- `SmartCore::Engine::Frozener` can not be used with rubies lower than `@2.7`;
|
20
|
+
|
21
|
+
## [0.8.0] - 2020-07-25
|
22
|
+
### Added
|
23
|
+
- Any object frozener (`SmartCore::Engine::Frozener`, `SmartCore::Engine::Frozener::Mixin`);
|
24
|
+
|
25
|
+
## [0.7.0] - 2020-07-03
|
26
|
+
### Added
|
27
|
+
- Atomic threadsafe value container (`SmartCore::Engine::Atom`);
|
28
|
+
|
29
|
+
## [0.6.0] - 2020-05-03
|
30
|
+
### Added
|
31
|
+
- Inline rescue pipe (`SmartCore::Engine::RescueExt.inline_rescue_pipe`);
|
32
|
+
- Actualized development dependencies and test environment;
|
33
|
+
|
34
|
+
## [0.5.0] - 2020-01-22
|
35
|
+
### Added
|
36
|
+
- Global error type `SmartCore::TypeError` inherited from `::TypeError`;
|
37
|
+
|
4
38
|
## [0.4.0] - 2020-01-19
|
5
39
|
### Added
|
6
40
|
- `SmartCore::Engine::Lock` - simple reentrant-based locking primitive;
|
data/Gemfile.lock
CHANGED
@@ -1,81 +1,102 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
smart_engine (0.
|
4
|
+
smart_engine (0.9.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
9
|
+
activesupport (6.1.0)
|
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.6.1)
|
16
|
+
rubocop (= 1.6.1)
|
17
|
+
rubocop-performance (= 1.9.1)
|
18
|
+
rubocop-rails (= 2.9.0)
|
19
|
+
rubocop-rake (= 0.5.1)
|
20
|
+
rubocop-rspec (= 2.0.1)
|
21
|
+
ast (2.4.1)
|
22
|
+
coderay (1.1.3)
|
23
|
+
concurrent-ruby (1.1.7)
|
24
|
+
diff-lcs (1.4.4)
|
25
|
+
docile (1.3.3)
|
26
|
+
i18n (1.8.5)
|
27
|
+
concurrent-ruby (~> 1.0)
|
28
|
+
method_source (1.0.0)
|
29
|
+
minitest (5.14.2)
|
30
|
+
parallel (1.20.1)
|
31
|
+
parser (2.7.2.0)
|
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
|
-
rake (13.0.
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
rspec-
|
35
|
-
|
36
|
-
rspec-
|
37
|
-
rspec-
|
38
|
+
rake (13.0.2)
|
39
|
+
regexp_parser (2.0.0)
|
40
|
+
rexml (3.2.4)
|
41
|
+
rspec (3.10.0)
|
42
|
+
rspec-core (~> 3.10.0)
|
43
|
+
rspec-expectations (~> 3.10.0)
|
44
|
+
rspec-mocks (~> 3.10.0)
|
45
|
+
rspec-core (3.10.0)
|
46
|
+
rspec-support (~> 3.10.0)
|
47
|
+
rspec-expectations (3.10.0)
|
38
48
|
diff-lcs (>= 1.2.0, < 2.0)
|
39
|
-
rspec-support (~> 3.
|
40
|
-
rspec-mocks (3.
|
49
|
+
rspec-support (~> 3.10.0)
|
50
|
+
rspec-mocks (3.10.0)
|
41
51
|
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
-
rspec-support (~> 3.
|
43
|
-
rspec-support (3.
|
44
|
-
rubocop (
|
45
|
-
jaro_winkler (~> 1.5.1)
|
52
|
+
rspec-support (~> 3.10.0)
|
53
|
+
rspec-support (3.10.0)
|
54
|
+
rubocop (1.6.1)
|
46
55
|
parallel (~> 1.10)
|
47
|
-
parser (>= 2.7.
|
56
|
+
parser (>= 2.7.1.5)
|
48
57
|
rainbow (>= 2.2.2, < 4.0)
|
58
|
+
regexp_parser (>= 1.8, < 3.0)
|
59
|
+
rexml
|
60
|
+
rubocop-ast (>= 1.2.0, < 2.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 (1.3.0)
|
64
|
+
parser (>= 2.7.1.5)
|
65
|
+
rubocop-performance (1.9.1)
|
66
|
+
rubocop (>= 0.90.0, < 2.0)
|
67
|
+
rubocop-ast (>= 0.4.0)
|
68
|
+
rubocop-rails (2.9.0)
|
69
|
+
activesupport (>= 4.2.0)
|
54
70
|
rack (>= 1.1)
|
55
|
-
rubocop (>= 0.
|
56
|
-
rubocop-rake (0.5.
|
71
|
+
rubocop (>= 0.90.0, < 2.0)
|
72
|
+
rubocop-rake (0.5.1)
|
57
73
|
rubocop
|
58
|
-
rubocop-rspec (
|
59
|
-
rubocop (
|
74
|
+
rubocop-rspec (2.0.1)
|
75
|
+
rubocop (~> 1.0)
|
76
|
+
rubocop-ast (>= 1.1.0)
|
60
77
|
ruby-progressbar (1.10.1)
|
61
|
-
simplecov (0.
|
78
|
+
simplecov (0.20.0)
|
62
79
|
docile (~> 1.1)
|
63
|
-
|
64
|
-
|
65
|
-
simplecov-html (0.
|
66
|
-
|
80
|
+
simplecov-html (~> 0.11)
|
81
|
+
simplecov_json_formatter (~> 0.1)
|
82
|
+
simplecov-html (0.12.3)
|
83
|
+
simplecov_json_formatter (0.1.2)
|
84
|
+
tzinfo (2.0.4)
|
85
|
+
concurrent-ruby (~> 1.0)
|
86
|
+
unicode-display_width (1.7.0)
|
87
|
+
zeitwerk (2.4.2)
|
67
88
|
|
68
89
|
PLATFORMS
|
69
90
|
ruby
|
70
91
|
|
71
92
|
DEPENDENCIES
|
72
|
-
armitage-rubocop (~>
|
93
|
+
armitage-rubocop (~> 1.6)
|
73
94
|
bundler (~> 2.1)
|
74
|
-
pry (~> 0.
|
95
|
+
pry (~> 0.13)
|
75
96
|
rake (~> 13.0)
|
76
|
-
rspec (~> 3.
|
77
|
-
simplecov (~> 0.
|
97
|
+
rspec (~> 3.10)
|
98
|
+
simplecov (~> 0.20)
|
78
99
|
smart_engine!
|
79
100
|
|
80
101
|
BUNDLED WITH
|
81
|
-
2.1.
|
102
|
+
2.1.4
|
data/README.md
CHANGED
@@ -23,7 +23,11 @@ require 'smart_core'
|
|
23
23
|
## Technologies
|
24
24
|
|
25
25
|
- [Global set of error types](#global-set-of-error-types)
|
26
|
-
- [Simple
|
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) (classic c-level `frozen?`/`freeze`)
|
29
|
+
- [Basic Object Refinements](#basic-object-refinements) (`SmartCore::Ext::BasicObjectAsObject`)
|
30
|
+
- [Inline rescue pipe](#inline-rescue-pipe)
|
27
31
|
|
28
32
|
---
|
29
33
|
|
@@ -33,10 +37,11 @@ require 'smart_core'
|
|
33
37
|
- `SmartCore::ArgumentError` (inherited from `::ArgumentError`);
|
34
38
|
- `SmartCore::FrozenError` (inherited from `::FrozenError`);
|
35
39
|
- `SmartCore::NameError` (inherited from `::NameError`);
|
40
|
+
- `SmartCore::TypeError` (inherited from `::TypeError`);
|
36
41
|
|
37
42
|
---
|
38
43
|
|
39
|
-
### Simple
|
44
|
+
### Simple reentrant lock
|
40
45
|
|
41
46
|
```ruby
|
42
47
|
lock = SmartCore::Engine::Lock.new
|
@@ -45,6 +50,136 @@ lock.synchronize { your_code }
|
|
45
50
|
|
46
51
|
---
|
47
52
|
|
53
|
+
### Atomic thread-safe value container
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
atom = SmartCore::Engine::Atom.new # initial value - nil
|
57
|
+
atom.value # => nil
|
58
|
+
# --- or ---
|
59
|
+
atom = SmartCore::Engine::Atom.new(7) # initial value - 7
|
60
|
+
atom.value # => 7
|
61
|
+
|
62
|
+
# set new value (thread-safely)
|
63
|
+
atom.swap { |original_value| original_value * 2 }
|
64
|
+
atom.value # => 14
|
65
|
+
```
|
66
|
+
|
67
|
+
---
|
68
|
+
|
69
|
+
### Any Object Frozener
|
70
|
+
|
71
|
+
- works with any type of ruby objects (event with `BasicObject`);
|
72
|
+
- uses classic Ruby C-level `frozen?`/`freeze` functionality;
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
# as a singleton
|
76
|
+
|
77
|
+
object = BasicObject.new
|
78
|
+
SmartCore::Engine::Frozener.frozen?(object) # => false
|
79
|
+
|
80
|
+
SmartCore::Engine::Frozener.freeze(object)
|
81
|
+
SmartCore::Engine::Frozener.frozen?(object) # => true
|
82
|
+
```
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
# as a mixin
|
86
|
+
|
87
|
+
class EmptyObject < BasicObject
|
88
|
+
include SmartCore::Engine::Frozener::Mixin
|
89
|
+
end
|
90
|
+
|
91
|
+
object = EmptyObject.new
|
92
|
+
|
93
|
+
object.frozen? # => false
|
94
|
+
object.freeze
|
95
|
+
object.frozen? # => true
|
96
|
+
```
|
97
|
+
|
98
|
+
---
|
99
|
+
|
100
|
+
### Basic Object Refinements
|
101
|
+
|
102
|
+
Ruby's `BasicObject` class does not have some fundamental (extremely important) methods:
|
103
|
+
|
104
|
+
- `is_a?` / `kind_of?`
|
105
|
+
- `freeze` / `frozen?`
|
106
|
+
|
107
|
+
`SmartCore::Ext::BasicObjectAsObject` refinement solves this problem.
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
# without refinement:
|
111
|
+
basic_obj = ::BasicObject.new
|
112
|
+
|
113
|
+
basic_obj.is_a?(::BasicObject) # raises ::NoMethodError
|
114
|
+
basic_obj.kind_of?(::BasicObject) # raises ::NoMethodError
|
115
|
+
basic_obj.freeze # raises ::NoMethodError
|
116
|
+
basic_obj.frozen? # raises ::NoMethodError
|
117
|
+
```
|
118
|
+
|
119
|
+
```ruby
|
120
|
+
# with refinement:
|
121
|
+
using SmartCore::Ext::BasicObjectAsObject
|
122
|
+
|
123
|
+
basic_obj = ::BasicObject.new
|
124
|
+
|
125
|
+
basic_obj.is_a?(::BasicObject) # => true
|
126
|
+
basic_obj.kind_of?(::BasicObject)
|
127
|
+
basic_obj.is_a?(::Integer) # => false
|
128
|
+
basic_obj.kind_of?(::Integer) # => false
|
129
|
+
|
130
|
+
basic_obj.frozen? # => false
|
131
|
+
basic_obj.freeze # => self
|
132
|
+
basic_obj.frozen? # => true
|
133
|
+
```
|
134
|
+
|
135
|
+
---
|
136
|
+
|
137
|
+
### Inline rescue pipe
|
138
|
+
|
139
|
+
- works with an array of proc objects;
|
140
|
+
- returns the result of the first non-failed proc;
|
141
|
+
- provides an error interception interface (a block argument);
|
142
|
+
- fails with the last failed proc exception (if all procs were failed and interceptor was not passed);
|
143
|
+
|
144
|
+
#### Return the result of the first non-failed proc
|
145
|
+
|
146
|
+
```ruby
|
147
|
+
SmartCore::Engine::RescueExt.inline_rescue_pipe(
|
148
|
+
-> { raise },
|
149
|
+
-> { raise },
|
150
|
+
-> { 123 },
|
151
|
+
-> { 567 },
|
152
|
+
-> { raise },
|
153
|
+
)
|
154
|
+
# => output: 123
|
155
|
+
```
|
156
|
+
|
157
|
+
#### Fail with the last failed proc exception
|
158
|
+
|
159
|
+
```ruby
|
160
|
+
SmartCore::Engine::RescueExt.inline_rescue_pipe(
|
161
|
+
-> { raise(::ArgumentError) },
|
162
|
+
-> { raise(::TypeError) },
|
163
|
+
-> { raise(::ZeroDivisionError) }
|
164
|
+
)
|
165
|
+
# => fails with ZeroDivisionError
|
166
|
+
```
|
167
|
+
|
168
|
+
#### Error interception
|
169
|
+
|
170
|
+
```ruby
|
171
|
+
SmartCore::Engine::RescueExt.inline_rescue_pipe(
|
172
|
+
-> { raise(::ArgumentError) },
|
173
|
+
-> { raise(::TypeError) },
|
174
|
+
-> { raise(::ZeroDivisionError, 'Intercepted exception') }
|
175
|
+
) do |error|
|
176
|
+
error.message
|
177
|
+
end
|
178
|
+
# => output: "Intercepted exception"
|
179
|
+
```
|
180
|
+
|
181
|
+
---
|
182
|
+
|
48
183
|
## Contributing
|
49
184
|
|
50
185
|
- Fork it ( https://github.com/smart-rb/smart_engine )
|
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.rb
CHANGED
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,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# @api public
|
4
|
+
# @since 0.8.0
|
5
|
+
# @version 0.9.0
|
6
|
+
module SmartCore::Engine::Frozener
|
7
|
+
# @api public
|
8
|
+
# @since 0.8.0
|
9
|
+
module Mixin
|
10
|
+
# @return [self]
|
11
|
+
#
|
12
|
+
# @api public
|
13
|
+
# @since 0.8.0
|
14
|
+
def freeze
|
15
|
+
SmartCore::Engine::Frozener.freeze(self)
|
16
|
+
end
|
17
|
+
|
18
|
+
# @return [Boolean]
|
19
|
+
#
|
20
|
+
# @api public
|
21
|
+
# @since 0.8.0
|
22
|
+
def frozen?
|
23
|
+
SmartCore::Engine::Frozener.frozen?(self)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# @return [UnboundMethod]
|
28
|
+
#
|
29
|
+
# @api private
|
30
|
+
# @since 0.8.0
|
31
|
+
FROZENER = Object.new.method(:freeze).unbind.tap(&:freeze)
|
32
|
+
|
33
|
+
# @return [UnboundMethod]
|
34
|
+
#
|
35
|
+
# @api private
|
36
|
+
# @since 0.8.0
|
37
|
+
FROZEN_CHECK = Object.new.method(:frozen?).unbind.tap(&:freeze)
|
38
|
+
|
39
|
+
class << self
|
40
|
+
# @param object [Any]
|
41
|
+
# @return [object]
|
42
|
+
#
|
43
|
+
# @api public
|
44
|
+
# @since 0.8.0
|
45
|
+
# @version 0.9.0
|
46
|
+
def freeze(object)
|
47
|
+
FROZENER.bind(object).call
|
48
|
+
end
|
49
|
+
|
50
|
+
# @param object [Any]
|
51
|
+
# @return [Boolean]
|
52
|
+
#
|
53
|
+
# @api public
|
54
|
+
# @since 0.8.0
|
55
|
+
# @version 0.9.0
|
56
|
+
def frozen?(object)
|
57
|
+
FROZEN_CHECK.bind(object).call
|
58
|
+
end
|
59
|
+
end
|
60
|
+
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
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# @api public
|
4
|
+
# @since 0.9.0
|
5
|
+
module SmartCore::Ext::BasicObjectAsObject
|
6
|
+
refine BasicObject do
|
7
|
+
_m_obj = ::Object.new
|
8
|
+
|
9
|
+
_is_a = _m_obj.method(:is_a?).unbind.tap(&:freeze)
|
10
|
+
_freeze = _m_obj.method(:freeze).unbind.tap(&:freeze)
|
11
|
+
_frozen = _m_obj.method(:frozen?).unbind.tap(&:freeze)
|
12
|
+
|
13
|
+
# @note Object#is_a? behavior copy
|
14
|
+
# @param klass [Class]
|
15
|
+
# @return [Boolean]
|
16
|
+
#
|
17
|
+
# @api public
|
18
|
+
# @since 0.9.0
|
19
|
+
define_method(:is_a?) do |klass|
|
20
|
+
_is_a.bind(self).call(klass)
|
21
|
+
end
|
22
|
+
alias_method :kind_of?, :is_a?
|
23
|
+
|
24
|
+
# @note Object#freeze behavior copy
|
25
|
+
# @return [self]
|
26
|
+
#
|
27
|
+
# @api public
|
28
|
+
# @since 0.9.0
|
29
|
+
define_method(:freeze) do
|
30
|
+
_freeze.bind(self).call
|
31
|
+
end
|
32
|
+
|
33
|
+
# @note Object#frozen? behavior copy
|
34
|
+
# @return [Boolean]
|
35
|
+
#
|
36
|
+
# @api public
|
37
|
+
# @since 0.9.0
|
38
|
+
define_method(:frozen?) do
|
39
|
+
_frozen.bind(self).call
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
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
|
@@ -36,8 +36,8 @@ Gem::Specification.new do |spec|
|
|
36
36
|
|
37
37
|
spec.add_development_dependency 'bundler', '~> 2.1'
|
38
38
|
spec.add_development_dependency 'rake', '~> 13.0'
|
39
|
-
spec.add_development_dependency 'rspec', '~> 3.
|
40
|
-
spec.add_development_dependency 'armitage-rubocop', '~>
|
41
|
-
spec.add_development_dependency 'simplecov', '~> 0.
|
42
|
-
spec.add_development_dependency 'pry', '~> 0.
|
39
|
+
spec.add_development_dependency 'rspec', '~> 3.10'
|
40
|
+
spec.add_development_dependency 'armitage-rubocop', '~> 1.6'
|
41
|
+
spec.add_development_dependency 'simplecov', '~> 0.20'
|
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.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rustam Ibragimov
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -44,56 +44,56 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '3.
|
47
|
+
version: '3.10'
|
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: '3.
|
54
|
+
version: '3.10'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: armitage-rubocop
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '1.6'
|
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: '
|
68
|
+
version: '1.6'
|
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.20'
|
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.20'
|
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,9 +119,15 @@ 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/ext.rb
|
124
|
+
- lib/smart_core/engine/frozener.rb
|
122
125
|
- lib/smart_core/engine/lock.rb
|
126
|
+
- lib/smart_core/engine/rescue_ext.rb
|
123
127
|
- lib/smart_core/engine/version.rb
|
124
128
|
- lib/smart_core/errors.rb
|
129
|
+
- lib/smart_core/ext.rb
|
130
|
+
- lib/smart_core/ext/basic_object_as_object.rb
|
125
131
|
- smart_engine.gemspec
|
126
132
|
homepage: https://github.com/smart-rb/smart_engine
|
127
133
|
licenses:
|
@@ -130,7 +136,7 @@ metadata:
|
|
130
136
|
homepage_uri: https://github.com/smart-rb/smart_engine
|
131
137
|
source_code_uri: https://github.com/smart-rb/smart_engine
|
132
138
|
changelog_uri: https://github.com/smart-rb/smart_engine/blob/master/CHANGELOG.md
|
133
|
-
post_install_message:
|
139
|
+
post_install_message:
|
134
140
|
rdoc_options: []
|
135
141
|
require_paths:
|
136
142
|
- lib
|
@@ -138,15 +144,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
138
144
|
requirements:
|
139
145
|
- - ">="
|
140
146
|
- !ruby/object:Gem::Version
|
141
|
-
version: 2.4.
|
147
|
+
version: 2.4.10
|
142
148
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
149
|
requirements:
|
144
150
|
- - ">="
|
145
151
|
- !ruby/object:Gem::Version
|
146
152
|
version: '0'
|
147
153
|
requirements: []
|
148
|
-
rubygems_version: 3.1.
|
149
|
-
signing_key:
|
154
|
+
rubygems_version: 3.1.4
|
155
|
+
signing_key:
|
150
156
|
specification_version: 4
|
151
157
|
summary: SmartCore Engine - a generic subset of SmartCore's functionality.
|
152
158
|
test_files: []
|