resol 0.5.1 → 0.6.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: 010d5a745816d85fe7754f0f8cf9ab9bc73803e5daf75b7a07e517b4d64c9432
4
- data.tar.gz: f939bbb9522f095651ef7ff15e050babb786eb4bc1d4d34d51644c6470ae8fb3
3
+ metadata.gz: 88557b0033bec108dc7f19bf2d6bd4bd7c7edbd79f6cd4f23257c9bc5b23856d
4
+ data.tar.gz: 3d25ee143170fd03b32421a560e7f6f3d353d2ced93f53748c9931ae1a10fcb8
5
5
  SHA512:
6
- metadata.gz: 5342c5148df6bf09ed709152d3962efe079dc7ae3fb88680e930a643bcdb24a1603ce4eb6ffb43780f0b65cfe9221ec2eadcf8269d28f42bb3d807066b0a2053
7
- data.tar.gz: f45af14da0c224877ccfa8f1f156d51f42c3f2e3a2e92f8aa336842a66e0cdb2c1c5b7df93448023d6df20891a8d7439b92d9dfd616d03356bf02dedf3d2923b
6
+ metadata.gz: e7424a06501000c75fe95e5f0b4397235594d8d0bbb2b16224ea0a5e456831e0c0b7e70c7a37d04a6bc43e1521e2a1585a711894ed11b6bf38a6f74a6e5583a0
7
+ data.tar.gz: 6c02d8eb6bb3d87f63ea4481f6d95b08a6c33e186ae501756443eee235eef2d1f358c677e99cdddcbf4bf431eed592fde9720087597905777cbcffb56514b010
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- resol (0.5.1)
4
+ resol (0.6.0)
5
5
  smart_initializer (~> 0.7)
6
6
 
7
7
  GEM
@@ -131,4 +131,4 @@ DEPENDENCIES
131
131
  simplecov-lcov
132
132
 
133
133
  BUNDLED WITH
134
- 2.2.19
134
+ 2.2.21
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.1"
4
+ VERSION = "0.6.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.1
4
+ version: 0.6.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-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: smart_initializer