smart_engine 0.6.0 → 0.7.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
2
  SHA256:
3
- metadata.gz: 5b137be2c542d4c01e946932a38f2de479072d1161b554371be67a2e05a7ecc7
4
- data.tar.gz: 2330b494ac201a1f41ee289a3dcd68acf326686c734b05c9b3e40980bf41c980
3
+ metadata.gz: fb49309ce61e395a7073af81c275aabdb9adbcf8d8b7d953da30aa87bafa7f20
4
+ data.tar.gz: 3e08590d5bce668b39ee3ea8893de436154dab189a6b528d1ca68156abbcb5b5
5
5
  SHA512:
6
- metadata.gz: 654494695f3f41c544a8aab9eaf65a2f682fb41252dcfcadbd02df058ffb9668ad3885a30176b80625058fbef0f4d343a679818a63d7d379d6ef54a4ccb16847
7
- data.tar.gz: 2179458ced3a67eb97649ed057943a4c1ad80df3ebda18f416ed7f3f350e8b5f75dfc111d442e57a920b9f1039e74fa3b99be74d4b76f7418caf2880a22e264f
6
+ metadata.gz: fe721dc23e1d34a4fac5a37e49e9909758d80605f6e8bdff145e3bf532439a26d192941638896c1d7da4fdec0c8dc9f879fadab4dae4b1a341a5ded4999cba26
7
+ data.tar.gz: f99856596971bb98fa521e1ee77a777f17bc7c7a6541477aa243f625e58e8f21d7f9a6d5bbadd51e38241cd05cb37b0e67a229bc3a3fe2459a3e2ae30a23ed85
@@ -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.7.0] - 2020-07-03
5
+ ### Added
6
+ - Atomic threadsafe value container (`SmartCore::Engine::Atom`);
7
+
4
8
  ## [0.6.0] - 2020-05-03
5
9
  ### Added
6
10
  - Inline rescue pipe (`SmartCore::Engine::RescueExt.inline_rescue_pipe`);
@@ -1,42 +1,42 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- smart_engine (0.6.0)
4
+ smart_engine (0.7.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- activesupport (6.0.2.2)
9
+ activesupport (6.0.3.2)
10
10
  concurrent-ruby (~> 1.0, >= 1.0.2)
11
11
  i18n (>= 0.7, < 2)
12
12
  minitest (~> 5.1)
13
13
  tzinfo (~> 1.1)
14
- zeitwerk (~> 2.2)
15
- armitage-rubocop (0.82.0.2)
16
- rubocop (= 0.82.0)
17
- rubocop-performance (= 1.5.2)
18
- rubocop-rails (= 2.5.2)
14
+ zeitwerk (~> 2.2, >= 2.2.2)
15
+ armitage-rubocop (0.85.1)
16
+ rubocop (= 0.85.1)
17
+ rubocop-performance (= 1.6.1)
18
+ rubocop-rails (= 2.6.0)
19
19
  rubocop-rake (= 0.5.1)
20
- rubocop-rspec (= 1.39.0)
21
- ast (2.4.0)
20
+ rubocop-rspec (= 1.40.0)
21
+ ast (2.4.1)
22
22
  coderay (1.1.2)
23
23
  concurrent-ruby (1.1.6)
24
- diff-lcs (1.3)
24
+ diff-lcs (1.4.4)
25
25
  docile (1.3.2)
26
- i18n (1.8.2)
26
+ i18n (1.8.3)
27
27
  concurrent-ruby (~> 1.0)
28
- jaro_winkler (1.5.4)
29
28
  method_source (1.0.0)
30
- minitest (5.14.0)
31
- parallel (1.19.1)
32
- parser (2.7.1.2)
33
- ast (~> 2.4.0)
29
+ minitest (5.14.1)
30
+ parallel (1.19.2)
31
+ parser (2.7.1.4)
32
+ ast (~> 2.4.1)
34
33
  pry (0.13.1)
35
34
  coderay (~> 1.1)
36
35
  method_source (~> 1.0)
37
- rack (2.2.2)
36
+ rack (2.2.3)
38
37
  rainbow (3.0.0)
39
38
  rake (13.0.1)
39
+ regexp_parser (1.7.1)
40
40
  rexml (3.2.4)
41
41
  rspec (3.9.0)
42
42
  rspec-core (~> 3.9.0)
@@ -44,30 +44,33 @@ GEM
44
44
  rspec-mocks (~> 3.9.0)
45
45
  rspec-core (3.9.2)
46
46
  rspec-support (~> 3.9.3)
47
- rspec-expectations (3.9.1)
47
+ rspec-expectations (3.9.2)
48
48
  diff-lcs (>= 1.2.0, < 2.0)
49
49
  rspec-support (~> 3.9.0)
50
50
  rspec-mocks (3.9.1)
51
51
  diff-lcs (>= 1.2.0, < 2.0)
52
52
  rspec-support (~> 3.9.0)
53
53
  rspec-support (3.9.3)
54
- rubocop (0.82.0)
55
- jaro_winkler (~> 1.5.1)
54
+ rubocop (0.85.1)
56
55
  parallel (~> 1.10)
57
56
  parser (>= 2.7.0.1)
58
57
  rainbow (>= 2.2.2, < 4.0)
58
+ regexp_parser (>= 1.7)
59
59
  rexml
60
+ rubocop-ast (>= 0.0.3)
60
61
  ruby-progressbar (~> 1.7)
61
62
  unicode-display_width (>= 1.4.0, < 2.0)
62
- rubocop-performance (1.5.2)
63
+ rubocop-ast (0.1.0)
64
+ parser (>= 2.7.0.1)
65
+ rubocop-performance (1.6.1)
63
66
  rubocop (>= 0.71.0)
64
- rubocop-rails (2.5.2)
65
- activesupport
67
+ rubocop-rails (2.6.0)
68
+ activesupport (>= 4.2.0)
66
69
  rack (>= 1.1)
67
- rubocop (>= 0.72.0)
70
+ rubocop (>= 0.82.0)
68
71
  rubocop-rake (0.5.1)
69
72
  rubocop
70
- rubocop-rspec (1.39.0)
73
+ rubocop-rspec (1.40.0)
71
74
  rubocop (>= 0.68.1)
72
75
  ruby-progressbar (1.10.1)
73
76
  simplecov (0.18.5)
@@ -78,13 +81,13 @@ GEM
78
81
  tzinfo (1.2.7)
79
82
  thread_safe (~> 0.1)
80
83
  unicode-display_width (1.7.0)
81
- zeitwerk (2.3.0)
84
+ zeitwerk (2.3.1)
82
85
 
83
86
  PLATFORMS
84
87
  ruby
85
88
 
86
89
  DEPENDENCIES
87
- armitage-rubocop (~> 0.82)
90
+ armitage-rubocop (~> 0.85)
88
91
  bundler (~> 2.1)
89
92
  pry (~> 0.13)
90
93
  rake (~> 13.0)
data/README.md CHANGED
@@ -24,6 +24,7 @@ require 'smart_core'
24
24
 
25
25
  - [Global set of error types](#global-set-of-error-types)
26
26
  - [Simple reentrant lock](#simple-reentrant-lock)
27
+ - [Atomic thread-safe value container](#atomic-thread-safe-value-container)
27
28
  - [Inline rescue pipe](#inline-rescue-pipe)
28
29
 
29
30
  ---
@@ -47,6 +48,22 @@ lock.synchronize { your_code }
47
48
 
48
49
  ---
49
50
 
51
+ ### Atomic thread-safe value container
52
+
53
+ ```ruby
54
+ atom = SmartCore::Engine::Atom.new # initial value - nil
55
+ atom.value # => nil
56
+ # --- or ---
57
+ atom = SmartCore::Engine::Atom.new(7) # initial value - 7
58
+ atom.value # => 7
59
+
60
+ # set new value (thread-safely)
61
+ atom.swap { |original_value| original_value * 2 }
62
+ atom.value # => 14
63
+ ```
64
+
65
+ ---
66
+
50
67
  ### Inline rescue pipe
51
68
 
52
69
  - works with an array of proc objects;
@@ -6,4 +6,5 @@ module SmartCore::Engine
6
6
  require_relative 'engine/version'
7
7
  require_relative 'engine/lock'
8
8
  require_relative 'engine/rescue_ext'
9
+ require_relative 'engine/atom'
9
10
  end
@@ -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
@@ -6,7 +6,7 @@ module SmartCore
6
6
  #
7
7
  # @api public
8
8
  # @since 0.1.0
9
- # @version 0.6.0
10
- VERSION = '0.6.0'
9
+ # @version 0.7.0
10
+ VERSION = '0.7.0'
11
11
  end
12
12
  end
@@ -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.82'
40
+ spec.add_development_dependency 'armitage-rubocop', '~> 0.85'
41
41
  spec.add_development_dependency 'simplecov', '~> 0.18'
42
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.6.0
4
+ version: 0.7.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-05-03 00:00:00.000000000 Z
11
+ date: 2020-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0.82'
61
+ version: '0.85'
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.82'
68
+ version: '0.85'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: simplecov
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -119,6 +119,7 @@ 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
122
123
  - lib/smart_core/engine/lock.rb
123
124
  - lib/smart_core/engine/rescue_ext.rb
124
125
  - lib/smart_core/engine/version.rb