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