handleit 1.1.3 → 1.2.6

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/handle.rb +18 -6
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bc355df87f74ad63f9fffdcc5ffb9482fc5e3c7f5d5415cc0cd6dc58070f624e
4
- data.tar.gz: c54dc82c7299f76dfd278d686cfd38defa4074483c534dbc79989974d0138f1b
3
+ metadata.gz: 2d1d9aa67b2978e194925dcbd564104257df6128cd764cf8b9cfc1fd79640584
4
+ data.tar.gz: 5ba49368ecba15844c3b749b9ce8a86c1cff4cbc9cb3adf6cd1d12dff4e4fd77
5
5
  SHA512:
6
- metadata.gz: 2033f523f28052c29b2dcbe014dc642cf2469163def8665d9ca311346139e146a1d4b83b5d2e2266aa0af1633fab325f1223d054a20927f2e6b3f1cf7595dbf9
7
- data.tar.gz: 6bbae8d1827bdf6e579b9b388f6ee03754c55b8454caacf8b8e67b17d6d620b71c647aaf7ac74399a893fc3b96d99e89a70809bed93a90526ddf148b5c923b09
6
+ metadata.gz: cd1bd74c1f31a555f151463869829ff6189db451571dea01427abf61edbe8601dd94d71050ecac19f774b9ad11f80014098a919c39432e96b62b3cb461d9a678
7
+ data.tar.gz: 9751753eca99dbdb8e5e9e8b69bc70281c850314cb16453e090459938f57a9ab3b560d884c14207fc9b6d8754ede86331563f086583e86db4588fd32071a05dc
data/lib/handle.rb CHANGED
@@ -13,16 +13,27 @@ class Handle
13
13
  validate(options)
14
14
 
15
15
  @result = OpenStruct.new return: yield, success: true, error: nil
16
+ @returns_pool = []
16
17
  self
17
18
  rescue StandardError => e
18
19
  error_handler(e)
19
20
  end
20
21
 
21
- def with
22
- @result.return = yield(@result.return, **options = {}) if success?
22
+ def with(args={})
23
+ args = args.slice(:on_fail)
24
+
25
+ if success?
26
+ @returns_pool << yield(@result.return, **options = {})
27
+ @result.return = @returns_pool.last
28
+ end
23
29
  self
24
30
  rescue StandardError => e
25
- error_handler(e)
31
+ if args[:on_fail] == :rollback
32
+ @result.return = @returns_pool.last
33
+ self
34
+ else
35
+ error_handler(e)
36
+ end
26
37
  end
27
38
 
28
39
  def on_fail
@@ -50,9 +61,10 @@ class Handle
50
61
  end
51
62
 
52
63
  def validate(options)
53
- condition = options[:when]
54
- condition_error = options[:error] || 'Not Valid!'
55
- good_to_go = condition&.respond_to?(:call) ? condition&.call : true
64
+ condition = options[:when].nil? || options[:when]
65
+ condition_error = options[:error] || options[:not_valid_error] || 'Not Valid!'
66
+ good_to_go = condition&.respond_to?(:call) ? condition&.call : condition
67
+
56
68
  raise NotValidError, condition_error unless good_to_go
57
69
  end
58
70
  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: 1.1.3
4
+ version: 1.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleg Saltykov
@@ -40,5 +40,5 @@ rubygems_version: 3.1.4
40
40
  signing_key:
41
41
  specification_version: 4
42
42
  summary: Handleit - promise like way of handling logic execution with ability of chaining
43
- handlers like in Elexir pipelining approach
43
+ handlers like in js promise, plus some useful additions like guard and rollback
44
44
  test_files: []