l43_core 0.3.0 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc6a45895d6fc02690315db7d89310741c5383e6d3a737ccf7ef6f0073edc742
4
- data.tar.gz: 59109ae8a0939d6969c10aacb7fb69a1bb5b71a3d5a958497d5f93cb2a9cbae3
3
+ metadata.gz: 898de12e76b1dee2bf836e6fee21ddf3a3756174ee40025cb52864ad1c9c301b
4
+ data.tar.gz: 76a116516d241067400e21342dcec21e7d699ff00232b6bdab0170a46585bf2b
5
5
  SHA512:
6
- metadata.gz: bedb03beb64d5dd5b2ec3925e49ae272b36a917f0625702fda24d7ccc972cde14080f7c2f092f3b58a082772cb588420042b765236b84891342789965ffe1d78
7
- data.tar.gz: fd72910b18052c124e830cbb57cb1622f90695e2f6b7cf2aa38d2332231e5645a65a7a820bffea5a72ae7c7744982021a06865189a9b147430b273c583e6faa4
6
+ metadata.gz: 994947aa5ce04cf804455cedf67e8cc8f83ff1c717d341a72c1bad15ae9baaba4da1c5c4ce6dbe2609d91fc81bc86f954fbb1bea6e86d8ee4bbcbbfd04496d7b
7
+ data.tar.gz: 1ee63369254fff6bf00614cd0a08882e966b7797f8988af1caec4737b1ee9ea5e71c41361d8fec3f7fb7bc9d14479da2315d3a9546ad7b98e44c3c321dcbd7dd
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module L43
4
+ module Core
5
+ class Fn
6
+ attr_reader :fn, :name
7
+
8
+ def call(*a, **k, &b) = fn.(*a, **k, &b)
9
+
10
+ def to_s = "Fn<#{name}>"
11
+
12
+ def ==(other)
13
+ return false unless self.class === other
14
+ other.name == name && other.fn == fn
15
+ end
16
+
17
+ private
18
+ def initialize(name, &b)
19
+ @fn = b
20
+ @name = name
21
+ end
22
+ end
23
+ end
24
+ end
25
+ # SPDX-License-Identifier: AGPL-3.0-or-later
@@ -1,14 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'l43'
3
4
  require 'l43/errors'
4
- require_relative 'result/constructors'
5
- require_relative 'result/failure'
6
- require_relative 'result/helpers'
7
- require_relative 'result/success'
5
+ # require_relative 'result/constructors'
6
+ # require_relative 'result/failure'
7
+ # require_relative 'result/helpers'
8
+ # require_relative 'result/success'
8
9
 
9
10
  module L43
10
11
  module Core
11
12
  module Result
13
+ L43.import_all("result/*")
12
14
  extend Constructors
13
15
  include Helpers
14
16
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module L43
4
4
  module Core
5
- VERSION = "0.3.0"
5
+ VERSION = "0.4.0"
6
6
  end
7
7
  end
8
8
  # SPDX-License-Identifier: AGPL-3.0-or-later
data/lib/l43/errors.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module L43
4
+ IllegalScope = Class.new(RuntimeError)
4
5
  IllegalState = Class.new(RuntimeError)
5
6
  AbstractMethod = Class.new(RuntimeError)
6
7
  module Core
data/lib/l43.rb CHANGED
@@ -1,6 +1,59 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module L43
3
+ require_relative 'l43/errors'
4
+ require_relative 'l43/core/fn'
5
+ module L43 extend self
6
+
7
+ def fn(name, &blk) = Core::Fn.new(name, &blk)
8
+
9
+ def import_all(glob, into: nil, namespace: "l43")
10
+ cl = caller_locations(1, 1).first.absolute_path
11
+ File.split(cl) => base, _file
12
+ raise IllegalScope, "import_all method can only be called from code inside the namespace #{namespace}" unless %r[.*/(?=#{namespace}/)].match?(base)
13
+ # p(base:, glob:)
14
+ glob = File.join(base, glob)
15
+ Dir.glob(glob).map do |file_path|
16
+ next if File.directory?(file_path)
17
+ next unless file_path.end_with?(".rb")
18
+ _import(file_path.sub(/\.rb\z/, ""), into:, namespace:)
19
+ end.compact
20
+ end
21
+
22
+ def import(path, into: nil, namespace: "l43")
23
+ cl = caller_locations(1, 1).first.absolute_path
24
+ File.split(cl) => base, _file
25
+ raise IllegalScope, "import method can only be called from code inside the namespace #{namespace}" unless %r[.*/(?=#{namespace}/)].match?(base)
26
+ file_path = File.join(base, path)
27
+ _import(file_path.sub(/\.rb\z/, ""), into:, namespace:)
28
+ end
29
+
30
+ private
31
+ def _file_to_const(file)
32
+ file.split("_").map(&:capitalize).join
33
+ end
34
+
35
+ def _import(path, into:, namespace:)
36
+ require(path)
37
+ const_name = _path_to_const(path, namespace:)
38
+ value = Kernel.const_get(const_name)
39
+ into.const_set(const_name.split("::").last, value) if into
40
+ value
41
+ end
42
+
43
+ def _path_to_const(path, namespace:)
44
+ # p(path:)
45
+ rel_path = path.sub(%r[.*/(?=#{namespace}/)], "")
46
+ rel_path.split("/").map do |seg|
47
+ _file_to_const(seg)
48
+ end.join("::")
49
+ end
50
+
51
+ def _relative_base(path, namespace:)
52
+ return path unless path.start_with?("/")
53
+
54
+ path.split("/#{namespace}/").last
55
+ end
56
+
4
57
 
5
58
  end
6
59
  # SPDX-License-Identifier: AGPL-3.0-or-later
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.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Dober
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2026-11-03 00:00:00.000000000 Z
10
+ date: 2026-11-10 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: ostruct
@@ -41,6 +41,7 @@ files:
41
41
  - lib/l43/core/enumerable_extensions.rb
42
42
  - lib/l43/core/extend_enumerable.rb
43
43
  - lib/l43/core/extend_object.rb
44
+ - lib/l43/core/fn.rb
44
45
  - lib/l43/core/forwarder.rb
45
46
  - lib/l43/core/none.rb
46
47
  - lib/l43/core/object_extensions.rb
@@ -51,7 +52,6 @@ files:
51
52
  - lib/l43/core/result/success.rb
52
53
  - lib/l43/core/version.rb
53
54
  - lib/l43/errors.rb
54
- - lib/l43/kernel.rb
55
55
  - lib/l43/open_struct.rb
56
56
  homepage: https://codeberg.org/lab419/l43_core
57
57
  licenses:
@@ -71,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
71
  - !ruby/object:Gem::Version
72
72
  version: '0'
73
73
  requirements: []
74
- rubygems_version: 4.0.20
74
+ rubygems_version: 4.0.23
75
75
  specification_version: 4
76
76
  summary: Core Functionality for L43 Ruby Tool
77
77
  test_files: []
data/lib/l43/kernel.rb DELETED
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Kernel
4
- def import_l43(path)
5
- require(File.join("l43", path))
6
-
7
- name = path.split("/").map do |seg|
8
- seg.split("_").map(&:capitalize).join
9
- end.join("::")
10
- Kernel.const_get("L43::#{name}")
11
- end
12
- end
13
- # SPDX-License-Identifier: AGPL-3.0-or-later