resol 0.5.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: 3e85fb79be6315df1a0073d5ee5b5c78dd18c2bc4b7f208c4bd72754f923ff13
4
- data.tar.gz: ee06e3e8d41e9800ddb12a9ba0392ab3d7e171ea66332f702a9c46126c6042c0
3
+ metadata.gz: 77dffd7c902fc23453017169fe4e817b133495404143604a804b37c684223241
4
+ data.tar.gz: 05a63f798b1635788e913cb156001d8244128567e6c868d6a82a84424c2bb091
5
5
  SHA512:
6
- metadata.gz: fef4615bf36c1bde74815e9e5db5e3c5ff3ae7bada67142207042096c150bba680227755568298893f1024d5c8aaf5a6e14fc3e164a4f07b9d0176d70a4271d2
7
- data.tar.gz: deeb6d29fdd34f3116df29f143134f44efd7d8f112ae07b9e564cf62e830b97171e9abae8edd03541b9f8e3aac6f1e43850d15c2d95d8d37374fbb5324bc1914
6
+ metadata.gz: a84fdcd1b22fd64fe1c6a5d3025d95de0ca9a10d60a1513ba6b10842638e6c1748abc1ae412d32098a7e3fc8cb53b33a69a21335523ee7d2c753adbc4673eff6
7
+ data.tar.gz: ad1d2be7635092e0ad39097bf570b31b63fec0841c0b8bcbe7459c893f4c8487cf3eda95eb404b7e26000a3276ea4de828f69696b31033fa4edcc3449dbf0bdc
data/Gemfile.lock CHANGED
@@ -1,20 +1,20 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- resol (0.5.0)
5
- smart_initializer (~> 0.5)
4
+ resol (0.7.0)
5
+ smart_initializer (~> 0.7)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activesupport (6.1.4)
10
+ activesupport (6.1.4.1)
11
11
  concurrent-ruby (~> 1.0, >= 1.0.2)
12
12
  i18n (>= 1.6, < 2)
13
13
  minitest (>= 5.1)
14
14
  tzinfo (~> 2.0)
15
15
  zeitwerk (~> 2.3)
16
16
  ast (2.4.2)
17
- bundler-audit (0.8.0)
17
+ bundler-audit (0.9.0.1)
18
18
  bundler (>= 1.2.0, < 3)
19
19
  thor (~> 1.0)
20
20
  ci-helper (0.4.2)
@@ -26,21 +26,21 @@ GEM
26
26
  concurrent-ruby (1.1.9)
27
27
  diff-lcs (1.4.4)
28
28
  docile (1.4.0)
29
- dry-inflector (0.2.0)
29
+ dry-inflector (0.2.1)
30
30
  i18n (1.8.10)
31
31
  concurrent-ruby (~> 1.0)
32
32
  method_source (1.0.0)
33
33
  minitest (5.14.4)
34
- parallel (1.20.1)
35
- parser (3.0.1.1)
34
+ parallel (1.21.0)
35
+ parser (3.0.2.0)
36
36
  ast (~> 2.4.1)
37
37
  pry (0.14.1)
38
38
  coderay (~> 1.1)
39
39
  method_source (~> 1.0)
40
- qonfig (0.25.0)
40
+ qonfig (0.26.0)
41
41
  rack (2.2.3)
42
42
  rainbow (3.0.0)
43
- rake (13.0.3)
43
+ rake (13.0.6)
44
44
  regexp_parser (2.1.1)
45
45
  rexml (3.2.5)
46
46
  rspec (3.10.0)
@@ -65,7 +65,7 @@ GEM
65
65
  rubocop-ast (>= 1.7.0, < 2.0)
66
66
  ruby-progressbar (~> 1.7)
67
67
  unicode-display_width (>= 1.4.0, < 3.0)
68
- rubocop-ast (1.7.0)
68
+ rubocop-ast (1.11.0)
69
69
  parser (>= 3.0.1.1)
70
70
  rubocop-config-umbrellio (1.17.0.53)
71
71
  rubocop (= 1.17.0)
@@ -89,7 +89,7 @@ GEM
89
89
  rubocop-sequel (0.2.0)
90
90
  rubocop (~> 1.0)
91
91
  ruby-progressbar (1.11.0)
92
- sequel (5.45.0)
92
+ sequel (5.48.0)
93
93
  simplecov (0.21.2)
94
94
  docile (~> 1.1)
95
95
  simplecov-html (~> 0.11)
@@ -102,7 +102,7 @@ GEM
102
102
  qonfig (~> 0.24)
103
103
  smart_engine (~> 0.11)
104
104
  smart_types (~> 0.4)
105
- smart_types (0.4.0)
105
+ smart_types (0.6.0)
106
106
  smart_engine (~> 0.11)
107
107
  symbiont-ruby (0.7.0)
108
108
  thor (1.1.0)
@@ -111,7 +111,7 @@ GEM
111
111
  umbrellio-sequel-plugins (0.5.1.27)
112
112
  sequel
113
113
  symbiont-ruby
114
- unicode-display_width (2.0.0)
114
+ unicode-display_width (2.1.0)
115
115
  zeitwerk (2.4.2)
116
116
 
117
117
  PLATFORMS
@@ -131,4 +131,4 @@ DEPENDENCIES
131
131
  simplecov-lcov
132
132
 
133
133
  BUNDLED WITH
134
- 2.2.19
134
+ 2.2.21
data/README.md CHANGED
@@ -99,9 +99,16 @@ Methods:
99
99
  - `failure?` – returns `true` for failure result and `false` for success result
100
100
  - `value!` – unwraps a result object, returns the value for success result, and throws an error for failure result
101
101
  - `value_or(other_value, &block)` – returns a value for success result or `other_value` for failure result (either calls `block` in case it given)
102
- - `or(&block)` - calls block for failure result, for success result does nothing
103
- - `either(success_proc, failure_proc)` - for success result calls success_proc with result value in args, for failure result calls failure_proc with error in args.
102
+ - `error` returns `nil` for success result and error object (with code and data) for failure result
103
+ - `or(&block)` calls block for failure result, for success result does nothing
104
+ - `either(success_proc, failure_proc)` – for success result calls success_proc with result value in args, for failure result calls failure_proc with error in args.
104
105
 
106
+ ### Error object
107
+
108
+ In case of failure you can get an error object with error code
109
+ and data from `fail!` arguments. This can be done by method `error` on
110
+ the result object and the returned object will have corresponding
111
+ methods `code` and `data`.
105
112
 
106
113
  ### Configuration
107
114
 
data/lib/resol/result.rb CHANGED
@@ -41,6 +41,10 @@ module Resol
41
41
  def value!
42
42
  @value
43
43
  end
44
+
45
+ def error
46
+ nil
47
+ end
44
48
  end
45
49
 
46
50
  class Failure < Result
@@ -68,6 +72,10 @@ module Resol
68
72
  def value!
69
73
  raise UnwrapError, "Failure result #{@value.inspect}"
70
74
  end
75
+
76
+ def error
77
+ @value
78
+ end
71
79
  end
72
80
 
73
81
  def self.Success(...)
data/lib/resol/service.rb CHANGED
@@ -8,58 +8,47 @@ module Resol
8
8
  class Service
9
9
  class InvalidCommandImplementation < StandardError; end
10
10
 
11
- class Interruption < StandardError
12
- attr_accessor :data
11
+ class Failure < StandardError
12
+ attr_accessor :data, :code
13
13
 
14
- def initialize(data)
14
+ def initialize(code, data)
15
+ self.code = code
15
16
  self.data = data
16
- super
17
+ super(data)
17
18
  end
18
19
 
19
20
  def inspect
20
21
  "#{self.class.name}: #{message}"
21
22
  end
22
23
 
23
- def message
24
- data.inspect
25
- end
26
- end
27
-
28
- class Failure < Interruption
29
- attr_accessor :code
30
-
31
- def initialize(code, data)
32
- self.code = code
33
- super(data)
34
- end
35
-
36
24
  def message
37
25
  data ? "#{code.inspect} => #{data.inspect}" : code.inspect
38
26
  end
39
27
  end
40
28
 
41
- class Success < Interruption; end
42
-
43
29
  include SmartCore::Initializer
44
30
  include Resol::Builder
45
31
  include Resol::Callbacks
46
32
 
33
+ Result = Struct.new(:data)
34
+
47
35
  class << self
48
36
  def inherited(klass)
49
37
  klass.const_set(:Failure, Class.new(klass::Failure))
50
- klass.const_set(:Success, Class.new(klass::Success))
51
38
  super
52
39
  end
53
40
 
54
41
  def call(*args, **kwargs, &block)
55
42
  command = build(*args, **kwargs)
56
- __run_callbacks__(command)
57
- command.call(&block)
43
+ result = catch(command) do
44
+ __run_callbacks__(command)
45
+ command.call(&block)
46
+ nil
47
+ end
48
+ return Resol::Success(result.data) unless result.nil?
58
49
 
59
50
  error_message = "No success! or fail! called in the #call method in #{command.class}"
60
51
  raise InvalidCommandImplementation, error_message
61
- rescue self::Success => e
62
- Resol::Success(e.data)
63
52
  rescue self::Failure => e
64
53
  Resol::Failure(e)
65
54
  end
@@ -78,7 +67,7 @@ module Resol
78
67
  end
79
68
 
80
69
  def success!(data = nil)
81
- raise self.class::Success.new(data)
70
+ throw(self, Result.new(data))
82
71
  end
83
72
  end
84
73
  end
data/lib/resol/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Resol
4
- VERSION = "0.5.0"
4
+ VERSION = "0.7.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resol
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aleksei Bespalov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-28 00:00:00.000000000 Z
11
+ date: 2021-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: smart_initializer
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.5'
19
+ version: '0.7'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.5'
26
+ version: '0.7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler-audit
29
29
  requirement: !ruby/object:Gem::Requirement