l43_core 0.1.2 → 0.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/l43/core/as_result.rb +21 -0
- data/lib/l43/core/result/helpers.rb +27 -0
- data/lib/l43/core/result.rb +36 -8
- data/lib/l43/core/version.rb +1 -1
- data/lib/l43/core.rb +2 -0
- metadata +5 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8f1dc19b0e66369e681dc2a7342ea49176148c78aab19832adbc814251f7b93a
|
|
4
|
+
data.tar.gz: d342f6c72085a6f5552930ec780fdd2111c7525fa18094f0e12e722ecc612825
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 45fa2391331c65b8337b47be2b7c28e8165a4acf16357fb272bb5d99a6cec7375c79ed8bc6502574ed262e0f40993b35a9932fbd3846e5d9e01b7cc81ed22f8d
|
|
7
|
+
data.tar.gz: a316c3d5fbff4b2fd0bfd8e856b3d4dfbc43c23ad48ab95a8d29070f3c9e4a52667e0ffcd03744ce88f305021c702261fced7e901f72e58d131c2608bba52b81
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'result'
|
|
4
|
+
module L43
|
|
5
|
+
module Core
|
|
6
|
+
module AsResult
|
|
7
|
+
include Result::Helpers
|
|
8
|
+
|
|
9
|
+
def self.extended(from)
|
|
10
|
+
from.include self
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def defresult(name, &blk)
|
|
14
|
+
define_method name do |*a, **k, &b|
|
|
15
|
+
as_result("method #{name}") { blk.(*a, **k, &b) }
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module L43
|
|
4
|
+
module Core
|
|
5
|
+
class Result
|
|
6
|
+
module Helpers
|
|
7
|
+
|
|
8
|
+
def as_result(message=nil, &blk)
|
|
9
|
+
Result.ok(blk.())
|
|
10
|
+
rescue StandardError => se
|
|
11
|
+
location = blk.source_location.join(':')
|
|
12
|
+
error = se.inspect
|
|
13
|
+
error = message + " (" + error + ")" if message
|
|
14
|
+
Result.error([error, "at", location].join(' '))
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def as_result_fn(message=nil, &blk)
|
|
18
|
+
-> (*a, **k, &b) do
|
|
19
|
+
as_result(message) { blk.(*a, **k, &b) }
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
# SPDX-License-Identifier: AGPL-3.0-or-later
|
data/lib/l43/core/result.rb
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'l43/core'
|
|
4
3
|
require 'l43/errors'
|
|
4
|
+
require_relative 'result/constructors'
|
|
5
|
+
require_relative 'result/helpers'
|
|
6
|
+
|
|
5
7
|
module L43
|
|
6
8
|
module Core
|
|
7
|
-
require_all __FILE__
|
|
8
9
|
class Result
|
|
9
10
|
extend Constructors
|
|
11
|
+
include Helpers
|
|
12
|
+
|
|
13
|
+
def ==(other)
|
|
14
|
+
return false unless self.class === other
|
|
15
|
+
|
|
16
|
+
to_h == other.to_h
|
|
17
|
+
end
|
|
10
18
|
|
|
11
19
|
def deconstruct(*)
|
|
12
20
|
if @ok
|
|
@@ -16,27 +24,47 @@ module L43
|
|
|
16
24
|
end
|
|
17
25
|
end
|
|
18
26
|
|
|
19
|
-
def
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
27
|
+
def error? = !@ok
|
|
28
|
+
|
|
29
|
+
def map(&blk)
|
|
30
|
+
return self unless @ok
|
|
31
|
+
blk.(self)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def map_result(&blk)
|
|
35
|
+
return self unless @ok
|
|
36
|
+
as_result('map_result') do
|
|
37
|
+
blk.(self)
|
|
24
38
|
end
|
|
25
39
|
end
|
|
26
40
|
|
|
27
|
-
def
|
|
41
|
+
def map_result!(&blk)
|
|
42
|
+
return self unless @ok
|
|
43
|
+
self.class.ok(blk.(self))
|
|
44
|
+
end
|
|
28
45
|
|
|
29
46
|
def message!
|
|
30
47
|
return @message unless @ok
|
|
31
48
|
raise IllegalState, "No error message in an ok result"
|
|
32
49
|
end
|
|
50
|
+
alias_method :message, :message!
|
|
33
51
|
|
|
34
52
|
def ok? = @ok
|
|
35
53
|
|
|
54
|
+
def to_h(*)
|
|
55
|
+
if @ok
|
|
56
|
+
{ok: @value}
|
|
57
|
+
else
|
|
58
|
+
{error: @message}
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
alias_method :deconstruct_keys, :to_h
|
|
62
|
+
|
|
36
63
|
def value!
|
|
37
64
|
return @value if @ok
|
|
38
65
|
raise IllegalState, "No value in an error result"
|
|
39
66
|
end
|
|
67
|
+
alias_method :value, :value!
|
|
40
68
|
end
|
|
41
69
|
end
|
|
42
70
|
end
|
data/lib/l43/core/version.rb
CHANGED
data/lib/l43/core.rb
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: l43_core
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Robert Dober
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2025-12-
|
|
10
|
+
date: 2025-12-10 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: ostruct
|
|
@@ -33,10 +33,12 @@ extra_rdoc_files: []
|
|
|
33
33
|
files:
|
|
34
34
|
- lib/l43.rb
|
|
35
35
|
- lib/l43/core.rb
|
|
36
|
+
- lib/l43/core/as_result.rb
|
|
36
37
|
- lib/l43/core/forwarder.rb
|
|
37
38
|
- lib/l43/core/none.rb
|
|
38
39
|
- lib/l43/core/result.rb
|
|
39
40
|
- lib/l43/core/result/constructors.rb
|
|
41
|
+
- lib/l43/core/result/helpers.rb
|
|
40
42
|
- lib/l43/core/version.rb
|
|
41
43
|
- lib/l43/errors.rb
|
|
42
44
|
- lib/l43/open_struct.rb
|
|
@@ -58,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
58
60
|
- !ruby/object:Gem::Version
|
|
59
61
|
version: '0'
|
|
60
62
|
requirements: []
|
|
61
|
-
rubygems_version:
|
|
63
|
+
rubygems_version: 4.0.1
|
|
62
64
|
specification_version: 4
|
|
63
65
|
summary: Core Functionality for L43 Ruby Tool
|
|
64
66
|
test_files: []
|