smart_engine 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 70cda20326ebd513f16c9d3ff9529b56f7e083b85a4843fe3f7640e7b8d1da1c
4
- data.tar.gz: 416c6ec9229b668b3cd6dbe779c99a80afe34debbc8d70dc9c0ac3c6d318348b
3
+ metadata.gz: fb49309ce61e395a7073af81c275aabdb9adbcf8d8b7d953da30aa87bafa7f20
4
+ data.tar.gz: 3e08590d5bce668b39ee3ea8893de436154dab189a6b528d1ca68156abbcb5b5
5
5
  SHA512:
6
- metadata.gz: 7fa576346189eaaaaa0e48818ee0688904c900792449c6595ca8885f428a18f345ab24b7257b4cc0c5b0b0842c9383e5d885572d37220b1a0a9dcaf5c6ccc11a
7
- data.tar.gz: 7386071b2ed63e7760747b8c7f0c5cbf01a78fc4f7e3c8442ac9c4139c924bd07300943383105589327c9b68365012829e9c9a7eac617f9455c44cc6f159ca0c
6
+ metadata.gz: fe721dc23e1d34a4fac5a37e49e9909758d80605f6e8bdff145e3bf532439a26d192941638896c1d7da4fdec0c8dc9f879fadab4dae4b1a341a5ded4999cba26
7
+ data.tar.gz: f99856596971bb98fa521e1ee77a777f17bc7c7a6541477aa243f625e58e8f21d7f9a6d5bbadd51e38241cd05cb37b0e67a229bc3a3fe2459a3e2ae30a23ed85
@@ -5,7 +5,7 @@ inherit_gem:
5
5
  - lib/rubocop.rspec.yml
6
6
 
7
7
  AllCops:
8
- TargetRubyVersion: 2.4.9
8
+ TargetRubyVersion: 2.7.1
9
9
  Include:
10
10
  - lib/**/*.rb
11
11
  - spec/**/*.rb
@@ -1,25 +1,21 @@
1
1
  ---
2
2
  language: ruby
3
3
  cache: bundler
4
- before_install: gem install bundler -v 2.1.2
4
+ before_install: gem install bundler
5
+ os: linux
6
+ dist: xenial
5
7
  script:
6
8
  - bundle exec rake rubocop
7
9
  - bundle exec rake rspec
8
10
  jobs:
9
11
  fast_finish: true
10
12
  include:
11
- - rvm: 2.4.9
12
- os: [linux, osx]
13
- - rvm: 2.5.7
14
- os: [linux, osx]
15
- - rvm: 2.6.5
16
- os: [linux, osx]
17
- - rvm: 2.7.0
18
- os: [linux, osx]
13
+ - rvm: 2.4.10
14
+ - rvm: 2.5.8
15
+ - rvm: 2.6.6
16
+ - rvm: 2.7.1
19
17
  - rvm: ruby-head
20
- os: [linux, osx]
21
18
  - rvm: jruby-head
22
- os: [linux, osx]
23
19
  allow_failures:
24
20
  - rvm: ruby-head
25
21
  - rvm: jruby-head
@@ -1,9 +1,36 @@
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
+
8
+ ## [0.6.0] - 2020-05-03
9
+ ### Added
10
+ - Inline rescue pipe (`SmartCore::Engine::RescueExt.inline_rescue_pipe`);
11
+ - Actualized development dependencies and test environment;
12
+
13
+ ## [0.5.0] - 2020-01-22
14
+ ### Added
15
+ - Global error type `SmartCore::TypeError` inherited from `::TypeError`;
16
+
17
+ ## [0.4.0] - 2020-01-19
18
+ ### Added
19
+ - `SmartCore::Engine::Lock` - simple reentrant-based locking primitive;
20
+
21
+ ## [0.3.0] - 2020-01-17
22
+ ### Added
23
+ - Global error type `SmartCore::NameError` inherited from `::NameError`;
24
+
25
+ ### Changed
26
+ - Actualized development dependencies;
27
+
28
+ ### Fixed
29
+ - Invalid gem requirement in `bin/console`;
30
+
4
31
  ## [0.2.0] - 2020-01-02
5
32
  ### Changed
6
- - `SmartCore::FrozenError` inherits classic `::FrozenError` behaviour for `Ruby >= 2.5.0` and old `::RuntimeError` behaviour for `Ruby < 2.5.0;
33
+ - `SmartCore::FrozenError` inherits classic `::FrozenError` behaviour for `Ruby >= 2.5.0` and old `::RuntimeError` behaviour for `Ruby < 2.5.0`;
7
34
 
8
35
  ## [0.1.0] - 2020-01-02
9
36
 
@@ -1,81 +1,99 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- smart_engine (0.2.0)
4
+ smart_engine (0.7.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- armitage-rubocop (0.78.0)
10
- rubocop (= 0.78.0)
11
- rubocop-performance (= 1.5.2)
12
- rubocop-rails (= 2.4.1)
13
- rubocop-rake (= 0.5.0)
14
- rubocop-rspec (= 1.37.1)
15
- ast (2.4.0)
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.85.1)
16
+ rubocop (= 0.85.1)
17
+ rubocop-performance (= 1.6.1)
18
+ rubocop-rails (= 2.6.0)
19
+ rubocop-rake (= 0.5.1)
20
+ rubocop-rspec (= 1.40.0)
21
+ ast (2.4.1)
16
22
  coderay (1.1.2)
17
- diff-lcs (1.3)
23
+ concurrent-ruby (1.1.6)
24
+ diff-lcs (1.4.4)
18
25
  docile (1.3.2)
19
- jaro_winkler (1.5.4)
20
- json (2.3.0)
21
- method_source (0.9.2)
22
- parallel (1.19.1)
23
- parser (2.7.0.0)
24
- ast (~> 2.4.0)
25
- pry (0.12.2)
26
- coderay (~> 1.1.0)
27
- method_source (~> 0.9.0)
28
- rack (2.0.8)
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.1)
36
- rspec-support (~> 3.9.1)
37
- rspec-expectations (3.9.0)
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
- rspec-mocks (3.9.0)
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.1)
44
- rubocop (0.78.0)
45
- jaro_winkler (~> 1.5.1)
53
+ rspec-support (3.9.3)
54
+ rubocop (0.85.1)
46
55
  parallel (~> 1.10)
47
- parser (>= 2.6)
56
+ parser (>= 2.7.0.1)
48
57
  rainbow (>= 2.2.2, < 4.0)
58
+ regexp_parser (>= 1.7)
59
+ rexml
60
+ rubocop-ast (>= 0.0.3)
49
61
  ruby-progressbar (~> 1.7)
50
- unicode-display_width (>= 1.4.0, < 1.7)
51
- rubocop-performance (1.5.2)
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.6.1)
52
66
  rubocop (>= 0.71.0)
53
- rubocop-rails (2.4.1)
67
+ rubocop-rails (2.6.0)
68
+ activesupport (>= 4.2.0)
54
69
  rack (>= 1.1)
55
- rubocop (>= 0.72.0)
56
- rubocop-rake (0.5.0)
70
+ rubocop (>= 0.82.0)
71
+ rubocop-rake (0.5.1)
57
72
  rubocop
58
- rubocop-rspec (1.37.1)
73
+ rubocop-rspec (1.40.0)
59
74
  rubocop (>= 0.68.1)
60
75
  ruby-progressbar (1.10.1)
61
- simplecov (0.17.1)
76
+ simplecov (0.18.5)
62
77
  docile (~> 1.1)
63
- json (>= 1.8, < 3)
64
- simplecov-html (~> 0.10.0)
65
- simplecov-html (0.10.2)
66
- unicode-display_width (1.6.0)
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.78)
90
+ armitage-rubocop (~> 0.85)
73
91
  bundler (~> 2.1)
74
- pry (~> 0.12)
92
+ pry (~> 0.13)
75
93
  rake (~> 13.0)
76
94
  rspec (~> 3.9)
77
- simplecov (~> 0.17)
95
+ simplecov (~> 0.18)
78
96
  smart_engine!
79
97
 
80
98
  BUNDLED WITH
81
- 2.1.2
99
+ 2.1.4
data/README.md CHANGED
@@ -20,6 +20,96 @@ require 'smart_core'
20
20
 
21
21
  ---
22
22
 
23
+ ## Technologies
24
+
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
+ - [Inline rescue pipe](#inline-rescue-pipe)
29
+
30
+ ---
31
+
32
+ ### Global set of error types
33
+
34
+ - `SmartCore::Error` (inherited from `::StandardError`);
35
+ - `SmartCore::ArgumentError` (inherited from `::ArgumentError`);
36
+ - `SmartCore::FrozenError` (inherited from `::FrozenError`);
37
+ - `SmartCore::NameError` (inherited from `::NameError`);
38
+ - `SmartCore::TypeError` (inherited from `::TypeError`);
39
+
40
+ ---
41
+
42
+ ### Simple reentrant lock
43
+
44
+ ```ruby
45
+ lock = SmartCore::Engine::Lock.new
46
+ lock.synchronize { your_code }
47
+ ```
48
+
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
+
67
+ ### Inline rescue pipe
68
+
69
+ - works with an array of proc objects;
70
+ - returns the result of the first non-failed proc;
71
+ - provides an error interception interface (a block argument);
72
+ - fails with the last failed proc exception (if all procs were failed and interceptor was not passed);
73
+
74
+ #### Return the result of the first non-failed proc
75
+
76
+ ```ruby
77
+ SmartCore::Engine::RescueExt.inline_rescue_pipe(
78
+ -> { raise },
79
+ -> { raise },
80
+ -> { 123 },
81
+ -> { 567 },
82
+ -> { raise },
83
+ )
84
+ # => output: 123
85
+ ```
86
+
87
+ #### Fail with the last failed proc exception
88
+
89
+ ```ruby
90
+ SmartCore::Engine::RescueExt.inline_rescue_pipe(
91
+ -> { raise(::ArgumentError) },
92
+ -> { raise(::TypeError) },
93
+ -> { raise(::ZeroDivisionError) }
94
+ )
95
+ # => fails with ZeroDivisionError
96
+ ```
97
+
98
+ #### Error interception
99
+
100
+ ```ruby
101
+ SmartCore::Engine::RescueExt.inline_rescue_pipe(
102
+ -> { raise(::ArgumentError) },
103
+ -> { raise(::TypeError) },
104
+ -> { raise(::ZeroDivisionError, 'Intercepted exception') }
105
+ ) do |error|
106
+ error.message
107
+ end
108
+ # => output: "Intercepted exception"
109
+ ```
110
+
111
+ ---
112
+
23
113
  ## Contributing
24
114
 
25
115
  - 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
 
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'bundler/setup'
5
- require 'smart_engine'
5
+ require 'smart_core'
6
6
 
7
7
  require 'pry'
8
8
  Pry.start
@@ -4,4 +4,7 @@
4
4
  # @since 0.1.0
5
5
  module SmartCore::Engine
6
6
  require_relative 'engine/version'
7
+ require_relative 'engine/lock'
8
+ require_relative 'engine/rescue_ext'
9
+ require_relative 'engine/atom'
7
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
@@ -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
@@ -6,6 +6,7 @@ module SmartCore
6
6
  #
7
7
  # @api public
8
8
  # @since 0.1.0
9
- VERSION = '0.2.0'
9
+ # @version 0.7.0
10
+ VERSION = '0.7.0'
10
11
  end
11
12
  end
@@ -9,6 +9,14 @@ module SmartCore
9
9
  # @since 0.1.0
10
10
  ArgumentError = Class.new(::ArgumentError)
11
11
 
12
+ # @api public
13
+ # @since 0.3.0
14
+ NameError = Class.new(::NameError)
15
+
16
+ # @api public
17
+ # @since 0.5.0
18
+ TypeError = Class.new(::TypeError)
19
+
12
20
  # @api public
13
21
  # @since 0.2.0
14
22
  FrozenError = begin # rubocop:disable Naming/ConstantName
@@ -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.9')
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.78'
41
- spec.add_development_dependency 'simplecov', '~> 0.17'
42
- spec.add_development_dependency 'pry', '~> 0.12'
40
+ spec.add_development_dependency 'armitage-rubocop', '~> 0.85'
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.2.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-01-02 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,42 +58,42 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0.78'
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.78'
68
+ version: '0.85'
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.17'
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.17'
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.12'
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.12'
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,9 @@ 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/lock.rb
124
+ - lib/smart_core/engine/rescue_ext.rb
122
125
  - lib/smart_core/engine/version.rb
123
126
  - lib/smart_core/errors.rb
124
127
  - smart_engine.gemspec
@@ -137,7 +140,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
137
140
  requirements:
138
141
  - - ">="
139
142
  - !ruby/object:Gem::Version
140
- version: 2.4.9
143
+ version: 2.4.10
141
144
  required_rubygems_version: !ruby/object:Gem::Requirement
142
145
  requirements:
143
146
  - - ">="