carton 0.2.0 → 0.3.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/CHANGELOG.md +75 -102
- data/README.md +50 -46
- data/lib/carton/activate_gems.rb +1 -1
- data/lib/carton/box.rb +89 -22
- data/lib/carton/error.rb +3 -2
- data/lib/carton/gem_activation.rb +51 -17
- data/lib/carton/import_cache.rb +61 -26
- data/lib/carton/kernel_patch.rb +5 -11
- data/lib/carton/loaded_features.rb +10 -0
- data/lib/carton/namespace.rb +78 -0
- data/lib/carton/{export_methods.rb → namespace_methods.rb} +13 -7
- data/lib/carton/resolver.rb +39 -10
- data/lib/carton/runtime.rb +36 -42
- data/lib/carton/version.rb +1 -1
- data/lib/carton.rb +3 -5
- data/sig/carton.rbs +11 -4
- metadata +9 -9
- data/lib/carton/export_declaration.rb +0 -72
- data/lib/carton/exports.rb +0 -54
data/sig/carton.rbs
CHANGED
|
@@ -3,8 +3,7 @@ module Kernel
|
|
|
3
3
|
|
|
4
4
|
def import: (::String path) -> untyped
|
|
5
5
|
def import_relative: (::String path) -> untyped
|
|
6
|
-
def export: (
|
|
7
|
-
def export_default: [T] (T value) -> T
|
|
6
|
+
def export: [T] (T value) -> T
|
|
8
7
|
end
|
|
9
8
|
|
|
10
9
|
module Carton
|
|
@@ -25,10 +24,12 @@ end
|
|
|
25
24
|
class Carton::GemfileNotFound < Carton::Error
|
|
26
25
|
end
|
|
27
26
|
|
|
28
|
-
|
|
27
|
+
# Lookup helpers on every `Carton::Namespace`. `carton rbs` extends its
|
|
28
|
+
# generated `Carton::Namespace::*` modules with these.
|
|
29
|
+
module Carton::NamespaceMethods
|
|
29
30
|
type key = ::String | ::Symbol
|
|
30
31
|
|
|
31
|
-
#
|
|
32
|
+
# Helpers come back as Method objects; constants as set.
|
|
32
33
|
def []: (key key) -> untyped
|
|
33
34
|
def deconstruct_keys: (nil keys) -> ::Hash[::Symbol, untyped]
|
|
34
35
|
| (::Array[::Symbol] keys) -> ::Hash[::Symbol, untyped]
|
|
@@ -36,7 +37,13 @@ class Carton::Exports < ::Module
|
|
|
36
37
|
| (key key, untyped default) -> untyped
|
|
37
38
|
| [T] (key key) { (key key) -> T } -> (untyped | T)
|
|
38
39
|
def fetch_values: (*key keys) -> ::Array[untyped]
|
|
40
|
+
def keys: () -> ::Array[::Symbol]
|
|
41
|
+
def to_h: () -> ::Hash[::Symbol, untyped]
|
|
39
42
|
def has_key?: (key key) -> bool
|
|
40
43
|
def key?: (key key) -> bool
|
|
41
44
|
def values_at: (*key keys) -> ::Array[untyped]
|
|
42
45
|
end
|
|
46
|
+
|
|
47
|
+
class Carton::Namespace < ::Module
|
|
48
|
+
include ::Carton::NamespaceMethods
|
|
49
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: carton
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- David Cristofaro
|
|
@@ -9,10 +9,10 @@ bindir: bin
|
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies: []
|
|
12
|
-
description:
|
|
13
|
-
Each Carton runs in its own Ruby::Box, so
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
description: The package system Ruby has been missing. Split code into Cartons that
|
|
13
|
+
import and export like modules. Each Carton runs in its own Ruby::Box, so only what
|
|
14
|
+
it exports is reachable, monkey patches stay where they are made, and two Cartons
|
|
15
|
+
can use different versions of the same gem. No manifest needed. Requires Ruby 4.0.7+.
|
|
16
16
|
email:
|
|
17
17
|
- david@dtcristo.com
|
|
18
18
|
executables: []
|
|
@@ -27,12 +27,12 @@ files:
|
|
|
27
27
|
- lib/carton/box.rb
|
|
28
28
|
- lib/carton/bundler.rb
|
|
29
29
|
- lib/carton/error.rb
|
|
30
|
-
- lib/carton/export_declaration.rb
|
|
31
|
-
- lib/carton/export_methods.rb
|
|
32
|
-
- lib/carton/exports.rb
|
|
33
30
|
- lib/carton/gem_activation.rb
|
|
34
31
|
- lib/carton/import_cache.rb
|
|
35
32
|
- lib/carton/kernel_patch.rb
|
|
33
|
+
- lib/carton/loaded_features.rb
|
|
34
|
+
- lib/carton/namespace.rb
|
|
35
|
+
- lib/carton/namespace_methods.rb
|
|
36
36
|
- lib/carton/resolver.rb
|
|
37
37
|
- lib/carton/runtime.rb
|
|
38
38
|
- lib/carton/version.rb
|
|
@@ -61,5 +61,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
61
61
|
requirements: []
|
|
62
62
|
rubygems_version: 4.0.20
|
|
63
63
|
specification_version: 4
|
|
64
|
-
summary:
|
|
64
|
+
summary: Real boundaries for Ruby
|
|
65
65
|
test_files: []
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Carton
|
|
4
|
-
# What an Entrypoint exports: an Export Namespace built from one or more
|
|
5
|
-
# `export` calls, or a single Default Export from `export_default`. The two
|
|
6
|
-
# forms are exclusive, and a name may be exported only once.
|
|
7
|
-
class ExportDeclaration
|
|
8
|
-
COMBINED =
|
|
9
|
-
'export_default cannot be combined with export; ' \
|
|
10
|
-
'put the other names inside the default value'
|
|
11
|
-
private_constant :COMBINED
|
|
12
|
-
|
|
13
|
-
NO_DEFAULT = Object.new.freeze
|
|
14
|
-
private_constant :NO_DEFAULT
|
|
15
|
-
|
|
16
|
-
def self.absent
|
|
17
|
-
new({}, {}, NO_DEFAULT)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def initialize(methods, values, default)
|
|
21
|
-
@methods = methods.freeze
|
|
22
|
-
@values = values.freeze
|
|
23
|
-
@default = default
|
|
24
|
-
freeze
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def add(methods, values)
|
|
28
|
-
raise ExportError, COMBINED if default?
|
|
29
|
-
|
|
30
|
-
duplicate =
|
|
31
|
-
(methods.keys + values.keys).find do |name|
|
|
32
|
-
@methods.key?(name) || @values.key?(name)
|
|
33
|
-
end
|
|
34
|
-
if duplicate
|
|
35
|
-
raise ExportError, "export name given more than once: #{duplicate}"
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
self.class.__send__(
|
|
39
|
-
:new,
|
|
40
|
-
@methods.merge(methods),
|
|
41
|
-
@values.merge(values),
|
|
42
|
-
NO_DEFAULT,
|
|
43
|
-
)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def default(value)
|
|
47
|
-
if default?
|
|
48
|
-
raise ExportError, 'export_default may be called only once per file'
|
|
49
|
-
end
|
|
50
|
-
raise ExportError, COMBINED if namespace?
|
|
51
|
-
|
|
52
|
-
self.class.__send__(:new, @methods, @values, value)
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
# The Default Export, or yields methods and values for the Export
|
|
56
|
-
# Namespace, or for a Bare Carton's surface, which `bare` computes lazily,
|
|
57
|
-
# when nothing was exported.
|
|
58
|
-
def public_surface(bare:)
|
|
59
|
-
return @default if default?
|
|
60
|
-
|
|
61
|
-
namespace? ? yield(@methods, @values) : yield(*bare.call)
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
private_class_method :new
|
|
65
|
-
|
|
66
|
-
private
|
|
67
|
-
|
|
68
|
-
def default? = !NO_DEFAULT.equal?(@default)
|
|
69
|
-
|
|
70
|
-
def namespace? = !(@methods.empty? && @values.empty?)
|
|
71
|
-
end
|
|
72
|
-
end
|
data/lib/carton/exports.rb
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Carton
|
|
4
|
-
# Module-like wrapper returned from named exports.
|
|
5
|
-
#
|
|
6
|
-
# Exported methods become singleton methods that forward to the carton's
|
|
7
|
-
# method. Capitalized value keys become constants; lowercase value keys become
|
|
8
|
-
# readers that return the value as-is. Lookup helpers return the `Method`
|
|
9
|
-
# object or the value.
|
|
10
|
-
class Exports < ::Module
|
|
11
|
-
include ExportMethods
|
|
12
|
-
|
|
13
|
-
def initialize(methods = {}, values = {})
|
|
14
|
-
super()
|
|
15
|
-
@lookup = {}
|
|
16
|
-
define_methods(methods)
|
|
17
|
-
define_values(values)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def deconstruct_keys(keys)
|
|
21
|
-
return super if keys
|
|
22
|
-
|
|
23
|
-
@lookup.to_h { |key, value| [key.to_sym, value] }
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
private
|
|
27
|
-
|
|
28
|
-
def define_methods(methods)
|
|
29
|
-
methods.each do |name, method|
|
|
30
|
-
@lookup[name.to_s] = method
|
|
31
|
-
define_singleton_method(name) do |*args, **kwargs, &block|
|
|
32
|
-
method.call(*args, **kwargs, &block)
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def define_values(values)
|
|
38
|
-
values.each do |key, value|
|
|
39
|
-
@lookup[key.to_s] = value
|
|
40
|
-
|
|
41
|
-
if key.to_s.match?(/\A[A-Z]/)
|
|
42
|
-
const_set(key, value)
|
|
43
|
-
else
|
|
44
|
-
define_singleton_method(key) { value }
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def lookup_entry(key)
|
|
50
|
-
name = key.to_s
|
|
51
|
-
@lookup.key?(name) ? [true, @lookup[name]] : [false, nil]
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|