smart_engine 0.5.0 → 0.6.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: 2487e6e6a99daf3e716d8a1d81a95ffb87c8461e510ce833e74ade673e56548c
4
- data.tar.gz: 7e66e448b6bb8a13b6720ca5d37ba673ac7e493f14460547c7dd3699d4aca90c
3
+ metadata.gz: 5b137be2c542d4c01e946932a38f2de479072d1161b554371be67a2e05a7ecc7
4
+ data.tar.gz: 2330b494ac201a1f41ee289a3dcd68acf326686c734b05c9b3e40980bf41c980
5
5
  SHA512:
6
- metadata.gz: 02a66ff6646a62f27f3c3d8416faa09a3d5dd32a35a8b47beb5f21b9914c09234a48d1500b126bb5c21903df7cbeb7ef79eab5533c586625c71778a2a9e5b0b1
7
- data.tar.gz: 74e2dd28fb809bd6f4d129c82350704e998a2ffc556f1ba1643d872f5bda3e0fdec596718e95ee812486ceb3139f951a06e61ea1b647740e34af8568c6a96241
6
+ metadata.gz: 654494695f3f41c544a8aab9eaf65a2f682fb41252dcfcadbd02df058ffb9668ad3885a30176b80625058fbef0f4d343a679818a63d7d379d6ef54a4ccb16847
7
+ data.tar.gz: 2179458ced3a67eb97649ed057943a4c1ad80df3ebda18f416ed7f3f350e8b5f75dfc111d442e57a920b9f1039e74fa3b99be74d4b76f7418caf2880a22e264f
@@ -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,18 +1,19 @@
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
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.9
13
- - rvm: 2.5.7
14
- - rvm: 2.6.5
15
- - rvm: 2.7.0
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:
@@ -1,6 +1,11 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [0.6.0] - 2020-05-03
5
+ ### Added
6
+ - Inline rescue pipe (`SmartCore::Engine::RescueExt.inline_rescue_pipe`);
7
+ - Actualized development dependencies and test environment;
8
+
4
9
  ## [0.5.0] - 2020-01-22
5
10
  ### Added
6
11
  - Global error type `SmartCore::TypeError` inherited from `::TypeError`;
@@ -1,81 +1,96 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- smart_engine (0.3.0)
4
+ smart_engine (0.6.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- armitage-rubocop (0.79.0)
10
- rubocop (= 0.79.0)
9
+ activesupport (6.0.2.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)
15
+ armitage-rubocop (0.82.0.2)
16
+ rubocop (= 0.82.0)
11
17
  rubocop-performance (= 1.5.2)
12
- rubocop-rails (= 2.4.1)
13
- rubocop-rake (= 0.5.0)
14
- rubocop-rspec (= 1.37.1)
18
+ rubocop-rails (= 2.5.2)
19
+ rubocop-rake (= 0.5.1)
20
+ rubocop-rspec (= 1.39.0)
15
21
  ast (2.4.0)
16
22
  coderay (1.1.2)
23
+ concurrent-ruby (1.1.6)
17
24
  diff-lcs (1.3)
18
25
  docile (1.3.2)
26
+ i18n (1.8.2)
27
+ concurrent-ruby (~> 1.0)
19
28
  jaro_winkler (1.5.4)
20
- json (2.3.0)
21
- method_source (0.9.2)
29
+ method_source (1.0.0)
30
+ minitest (5.14.0)
22
31
  parallel (1.19.1)
23
- parser (2.7.0.2)
32
+ parser (2.7.1.2)
24
33
  ast (~> 2.4.0)
25
- pry (0.12.2)
26
- coderay (~> 1.1.0)
27
- method_source (~> 0.9.0)
28
- rack (2.1.1)
34
+ pry (0.13.1)
35
+ coderay (~> 1.1)
36
+ method_source (~> 1.0)
37
+ rack (2.2.2)
29
38
  rainbow (3.0.0)
30
39
  rake (13.0.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.1)
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.2)
44
- rubocop (0.79.0)
53
+ rspec-support (3.9.3)
54
+ rubocop (0.82.0)
45
55
  jaro_winkler (~> 1.5.1)
46
56
  parallel (~> 1.10)
47
57
  parser (>= 2.7.0.1)
48
58
  rainbow (>= 2.2.2, < 4.0)
59
+ rexml
49
60
  ruby-progressbar (~> 1.7)
50
- unicode-display_width (>= 1.4.0, < 1.7)
61
+ unicode-display_width (>= 1.4.0, < 2.0)
51
62
  rubocop-performance (1.5.2)
52
63
  rubocop (>= 0.71.0)
53
- rubocop-rails (2.4.1)
64
+ rubocop-rails (2.5.2)
65
+ activesupport
54
66
  rack (>= 1.1)
55
67
  rubocop (>= 0.72.0)
56
- rubocop-rake (0.5.0)
68
+ rubocop-rake (0.5.1)
57
69
  rubocop
58
- rubocop-rspec (1.37.1)
70
+ rubocop-rspec (1.39.0)
59
71
  rubocop (>= 0.68.1)
60
72
  ruby-progressbar (1.10.1)
61
- simplecov (0.17.1)
73
+ simplecov (0.18.5)
62
74
  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.1)
75
+ simplecov-html (~> 0.11)
76
+ simplecov-html (0.12.2)
77
+ thread_safe (0.3.6)
78
+ tzinfo (1.2.7)
79
+ thread_safe (~> 0.1)
80
+ unicode-display_width (1.7.0)
81
+ zeitwerk (2.3.0)
67
82
 
68
83
  PLATFORMS
69
84
  ruby
70
85
 
71
86
  DEPENDENCIES
72
- armitage-rubocop (~> 0.79)
87
+ armitage-rubocop (~> 0.82)
73
88
  bundler (~> 2.1)
74
- pry (~> 0.12)
89
+ pry (~> 0.13)
75
90
  rake (~> 13.0)
76
91
  rspec (~> 3.9)
77
- simplecov (~> 0.17)
92
+ simplecov (~> 0.18)
78
93
  smart_engine!
79
94
 
80
95
  BUNDLED WITH
81
- 2.1.2
96
+ 2.1.4
data/README.md CHANGED
@@ -23,7 +23,8 @@ require 'smart_core'
23
23
  ## Technologies
24
24
 
25
25
  - [Global set of error types](#global-set-of-error-types)
26
- - [Simple reenternant lock](#simple-reenternant-lock)
26
+ - [Simple reentrant lock](#simple-reentrant-lock)
27
+ - [Inline rescue pipe](#inline-rescue-pipe)
27
28
 
28
29
  ---
29
30
 
@@ -37,7 +38,7 @@ require 'smart_core'
37
38
 
38
39
  ---
39
40
 
40
- ### Simple reenternant lock
41
+ ### Simple reentrant lock
41
42
 
42
43
  ```ruby
43
44
  lock = SmartCore::Engine::Lock.new
@@ -46,6 +47,52 @@ lock.synchronize { your_code }
46
47
 
47
48
  ---
48
49
 
50
+ ### Inline rescue pipe
51
+
52
+ - works with an array of proc objects;
53
+ - returns the result of the first non-failed proc;
54
+ - provides an error interception interface (a block argument);
55
+ - fails with the last failed proc exception (if all procs were failed and interceptor was not passed);
56
+
57
+ #### Return the result of the first non-failed proc
58
+
59
+ ```ruby
60
+ SmartCore::Engine::RescueExt.inline_rescue_pipe(
61
+ -> { raise },
62
+ -> { raise },
63
+ -> { 123 },
64
+ -> { 567 },
65
+ -> { raise },
66
+ )
67
+ # => output: 123
68
+ ```
69
+
70
+ #### Fail with the last failed proc exception
71
+
72
+ ```ruby
73
+ SmartCore::Engine::RescueExt.inline_rescue_pipe(
74
+ -> { raise(::ArgumentError) },
75
+ -> { raise(::TypeError) },
76
+ -> { raise(::ZeroDivisionError) }
77
+ )
78
+ # => fails with ZeroDivisionError
79
+ ```
80
+
81
+ #### Error interception
82
+
83
+ ```ruby
84
+ SmartCore::Engine::RescueExt.inline_rescue_pipe(
85
+ -> { raise(::ArgumentError) },
86
+ -> { raise(::TypeError) },
87
+ -> { raise(::ZeroDivisionError, 'Intercepted exception') }
88
+ ) do |error|
89
+ error.message
90
+ end
91
+ # => output: "Intercepted exception"
92
+ ```
93
+
94
+ ---
95
+
49
96
  ## Contributing
50
97
 
51
98
  - 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
 
@@ -5,4 +5,5 @@
5
5
  module SmartCore::Engine
6
6
  require_relative 'engine/version'
7
7
  require_relative 'engine/lock'
8
+ require_relative 'engine/rescue_ext'
8
9
  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,7 +6,7 @@ module SmartCore
6
6
  #
7
7
  # @api public
8
8
  # @since 0.1.0
9
- # @version 0.5.0
10
- VERSION = '0.5.0'
9
+ # @version 0.6.0
10
+ VERSION = '0.6.0'
11
11
  end
12
12
  end
@@ -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.79'
41
- spec.add_development_dependency 'simplecov', '~> 0.17'
42
- spec.add_development_dependency 'pry', '~> 0.12'
40
+ spec.add_development_dependency 'armitage-rubocop', '~> 0.82'
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.5.0
4
+ version: 0.6.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-22 00:00:00.000000000 Z
11
+ date: 2020-05-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.79'
61
+ version: '0.82'
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.79'
68
+ version: '0.82'
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
 
@@ -120,6 +120,7 @@ files:
120
120
  - lib/smart_core.rb
121
121
  - lib/smart_core/engine.rb
122
122
  - lib/smart_core/engine/lock.rb
123
+ - lib/smart_core/engine/rescue_ext.rb
123
124
  - lib/smart_core/engine/version.rb
124
125
  - lib/smart_core/errors.rb
125
126
  - smart_engine.gemspec
@@ -138,7 +139,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
138
139
  requirements:
139
140
  - - ">="
140
141
  - !ruby/object:Gem::Version
141
- version: 2.4.9
142
+ version: 2.4.10
142
143
  required_rubygems_version: !ruby/object:Gem::Requirement
143
144
  requirements:
144
145
  - - ">="