smart_core 0.2.0 → 0.3.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 +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +1 -1
- data/lib/smart_core/operation/exceptions.rb +20 -0
- data/lib/smart_core/operation/fatal.rb +21 -0
- data/lib/smart_core/operation/instance_builder.rb +3 -0
- data/lib/smart_core/operation.rb +15 -1
- data/lib/smart_core/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d5fabab611add86958e30b6ee5b01323f0bf9d25d1dc810a6b425551f6724f07
|
4
|
+
data.tar.gz: dd2568de8356fe185579a20adf5778672b84edebfe20145b71fe5ecc3ace07a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ed05efd0358bb94a3eafb8cfb4f4f719a163976ff9d55fe12dc85133173fc02cdfa2d658d51cc1c8109714f17babacdbad3bc77e8261586dcdc2cc3b5734187
|
7
|
+
data.tar.gz: 5e47ae0423372cd64d2dade6dad06b00d8faa6dce6a7a52ded5764001ac894c1c3eafb023c7d2babad7662561a4887c30c1b0820b71d4606357f76f66d4ba0ad
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
# Changelog
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## [0.3.0] - 2019-01-20
|
5
|
+
### Added
|
6
|
+
- **Operation**
|
7
|
+
- New result object type: `Fatal` (`SmartCore::Operation::Fatal`, `#Fatal`)
|
8
|
+
- stops the operation execution flow and returns
|
9
|
+
`SmartCore::Operation::Fatal` result immidietly;
|
10
|
+
- has `Failure`-like instantiation behavior and internal state (`#failure?`, `#fatal?`, `#errors`);
|
11
|
+
|
4
12
|
## [0.2.0] - 2019-01-20
|
5
13
|
### Added
|
6
14
|
- **Service object** abstraction (`SmartCore::Operation`);
|
data/README.md
CHANGED
@@ -26,7 +26,7 @@ require 'smart_core'
|
|
26
26
|
|
27
27
|
- [**Operation Object**](#operation-object) (aka `Service Object`) (`SmartCore::Operation`)
|
28
28
|
- attribute definition DSL (`param`, `option`, `params`, `options`);
|
29
|
-
- yieldable result object abstraction (`Success`, `Failure`, `#success?`, `#failure?`);
|
29
|
+
- yieldable result object abstraction (`Success`, `Failure`, `Fatal`, `#success?`, `#failure?`, `#fatal?`);
|
30
30
|
- yieldable `#call` (and `.call`);
|
31
31
|
- inheritance works as expected `:)`;
|
32
32
|
- no dependencies;
|
@@ -5,6 +5,26 @@ class SmartCore::Operation
|
|
5
5
|
# @since 0.2.0
|
6
6
|
Error = Class.new(StandardError)
|
7
7
|
|
8
|
+
# @api public
|
9
|
+
# @since 0.3.0
|
10
|
+
FatalError = Class.new(Error) do
|
11
|
+
# @return [SmartCore::Operation::Fatal]
|
12
|
+
#
|
13
|
+
# @api private
|
14
|
+
# @since 0.3.0
|
15
|
+
attr_reader :__operation_result__
|
16
|
+
|
17
|
+
# @param operation_result [SmartCore::Operation::Fatal]
|
18
|
+
# @return [void]
|
19
|
+
#
|
20
|
+
# @api private
|
21
|
+
# @since 0.3.0
|
22
|
+
def initialize(operation_result)
|
23
|
+
@__operation_result__ = operation_result
|
24
|
+
super()
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
8
28
|
# @api public
|
9
29
|
# @since 0.2.0
|
10
30
|
ArgumentError = Class.new(::ArgumentError)
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# @api public
|
4
|
+
# @since 0.3.0
|
5
|
+
class SmartCore::Operation::Fatal < SmartCore::Operation::Failure
|
6
|
+
# @return [SmartCore::Operation::FatalError]
|
7
|
+
#
|
8
|
+
# @api private
|
9
|
+
# @since 0.3.0
|
10
|
+
def exception
|
11
|
+
SmartCore::Operation::FatalError.new(self)
|
12
|
+
end
|
13
|
+
|
14
|
+
# @return [Boolean]
|
15
|
+
#
|
16
|
+
# @api public
|
17
|
+
# @since 0.3.0
|
18
|
+
def fatal?
|
19
|
+
true.tap { yield(self) if block_given? }
|
20
|
+
end
|
21
|
+
end
|
@@ -155,6 +155,9 @@ class SmartCore::Operation::InstanceBuilder
|
|
155
155
|
operation_object.singleton_class.prepend(Module.new do
|
156
156
|
def call
|
157
157
|
super.tap { |result| yield(result) if block_given? }
|
158
|
+
rescue SmartCore::Operation::FatalError => error
|
159
|
+
# NOTE: returns SmartCore::Operation::Fatal instance
|
160
|
+
error.__operation_result__.tap { |result| yield(result) if block_given? }
|
158
161
|
end
|
159
162
|
end)
|
160
163
|
end
|
data/lib/smart_core/operation.rb
CHANGED
@@ -9,6 +9,7 @@ class SmartCore::Operation
|
|
9
9
|
require_relative 'operation/result'
|
10
10
|
require_relative 'operation/success'
|
11
11
|
require_relative 'operation/failure'
|
12
|
+
require_relative 'operation/fatal'
|
12
13
|
require_relative 'operation/instance_builder'
|
13
14
|
require_relative 'operation/attribute_definer'
|
14
15
|
require_relative 'operation/initialization_dsl'
|
@@ -35,7 +36,9 @@ class SmartCore::Operation
|
|
35
36
|
# @since 0.2.0
|
36
37
|
def initialize(*, **); end
|
37
38
|
|
38
|
-
# @return [SmartCore::Operation::Success
|
39
|
+
# @return [SmartCore::Operation::Success]
|
40
|
+
# @return [SmartCore::Operation::Failure]
|
41
|
+
# @return [SmartCore::Operation::Fatal]
|
39
42
|
#
|
40
43
|
# @api public
|
41
44
|
# @since 0.2.0
|
@@ -62,4 +65,15 @@ class SmartCore::Operation
|
|
62
65
|
def Failure(*errors) # rubocop:disable Naming/MethodName
|
63
66
|
SmartCore::Operation::Failure.new(*errors)
|
64
67
|
end
|
68
|
+
|
69
|
+
# @param errors [Array<Symbol|Any>]
|
70
|
+
# @return [SmartCore::Operation::Fatal]
|
71
|
+
#
|
72
|
+
# @raise [SmartCore::Operation::FatalError]
|
73
|
+
#
|
74
|
+
# @api public
|
75
|
+
# @since 0.2.0
|
76
|
+
def Fatal(*errors) # rubocop:disable Naming/MethodName
|
77
|
+
raise SmartCore::Operation::Fatal.new(*errors)
|
78
|
+
end
|
65
79
|
end
|
data/lib/smart_core/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smart_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rustam Ibragimov
|
@@ -134,6 +134,7 @@ files:
|
|
134
134
|
- lib/smart_core/operation/attribute_set.rb
|
135
135
|
- lib/smart_core/operation/exceptions.rb
|
136
136
|
- lib/smart_core/operation/failure.rb
|
137
|
+
- lib/smart_core/operation/fatal.rb
|
137
138
|
- lib/smart_core/operation/initialization_dsl.rb
|
138
139
|
- lib/smart_core/operation/instance_builder.rb
|
139
140
|
- lib/smart_core/operation/result.rb
|