handleit 0.0.2 → 1.1.4
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/lib/handle.rb +26 -7
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48abe8d4e518fe2fd5a145caddbaeb5c846bab5336b9664946860be23fffc3d0
|
4
|
+
data.tar.gz: fe9d07b6970a8cec47d9ede62d01940f8bf27b366293fe2d79a6a3c8a69bed6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8bde98288716def4af2cc092b38fbbe053fd0408e6e66e0922d266e8a7cfc463e29b3744c13f36c943fc66feb7144c5000e6deece828ab66a2039ac8a0b656b
|
7
|
+
data.tar.gz: 3fc08d3a9cb26f8cb89075513d8b3ee28380609a6114916d1c37cd7247cc0216b337f4efe87d0f1b3472d8c21932abb0cd6409006a780d211cfda42fe376cbb8
|
data/lib/handle.rb
CHANGED
@@ -1,27 +1,32 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class Handle
|
4
|
+
NotValidError = Class.new(StandardError)
|
5
|
+
|
4
6
|
class << self
|
5
|
-
def it(&block)
|
6
|
-
new.it(&block)
|
7
|
+
def it(options = {}, &block)
|
8
|
+
new.it(options, &block)
|
7
9
|
end
|
8
10
|
end
|
9
11
|
|
10
|
-
def it
|
12
|
+
def it(options)
|
13
|
+
validate(options)
|
14
|
+
|
11
15
|
@result = OpenStruct.new return: yield, success: true, error: nil
|
12
16
|
self
|
13
17
|
rescue StandardError => e
|
14
|
-
|
15
|
-
self
|
18
|
+
error_handler(e)
|
16
19
|
end
|
17
20
|
|
18
21
|
def with
|
19
|
-
@result.return = yield(@result.return) if
|
22
|
+
@result.return = yield(@result.return, **options = {}) if success?
|
20
23
|
self
|
24
|
+
rescue StandardError => e
|
25
|
+
error_handler(e)
|
21
26
|
end
|
22
27
|
|
23
28
|
def on_fail
|
24
|
-
yield(@result.error) unless
|
29
|
+
yield(@result.error, **options = {}) unless success?
|
25
30
|
self
|
26
31
|
end
|
27
32
|
|
@@ -36,4 +41,18 @@ class Handle
|
|
36
41
|
def error
|
37
42
|
@result.error
|
38
43
|
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def error_handler(err)
|
48
|
+
@result = OpenStruct.new return: nil, success: false, error: err
|
49
|
+
self
|
50
|
+
end
|
51
|
+
|
52
|
+
def validate(options)
|
53
|
+
condition = options[:when] || true
|
54
|
+
condition_error = options[:error] || options[:not_valid_error] || 'Not Valid!'
|
55
|
+
good_to_go = condition&.respond_to?(:call) ? condition&.call : condition
|
56
|
+
raise NotValidError, condition_error unless good_to_go
|
57
|
+
end
|
39
58
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: handleit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oleg Saltykov
|
@@ -39,5 +39,6 @@ requirements: []
|
|
39
39
|
rubygems_version: 3.1.4
|
40
40
|
signing_key:
|
41
41
|
specification_version: 4
|
42
|
-
summary: Handleit - promise like way of handling logic execution
|
42
|
+
summary: Handleit - promise like way of handling logic execution with ability of chaining
|
43
|
+
handlers like in Elexir pipelining approach
|
43
44
|
test_files: []
|