core-loader 0.0.1 → 0.1.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: 18803ea5abfeac3a400b7bc7749532631b3e047de245c938fa133c4f552a1371
4
- data.tar.gz: 8f9568aae0a38e4306c424e4f753311ac110c3052e1581105a9777740fc13dc0
3
+ metadata.gz: c5a9a91c437fb1cf4033d6fc70b98d4f9ab1784360838ce84e83ad6b10ad62ee
4
+ data.tar.gz: 28995fde28e2505ca1072b26e5bbeb8333c55fd7f9a32cd176b78ac198166e79
5
5
  SHA512:
6
- metadata.gz: 0f30df18e52ad6c66f83e569b44de45dc17fb909b5d876ed1af9f474d9f011cca75d1d0a9e6d519331ea176eb48e35ead9e7ef5f3c5f15932dcc9d23bbeb4283
7
- data.tar.gz: 2d3b180dd56d27cc69af5063b0177245ae0376308a739cc95550c9fb1818292f2d7bbb9b3e479608c2cd8eb738a0d13ad337d79c57e721228932020d3c4c32f1
6
+ metadata.gz: b3f580e3494670b72240c3be121bc9cb82da7e9d51a729d8c5c788e20d8a8adc5cfa96fd15dc2b93604d0db3cb40b6b4dce8231c2775060ad4df8d4d8b1a7463
7
+ data.tar.gz: 8968a6d6a4622db48d41008f1df346fe9fb1cd2780ecfd56a883a0bed3a15474080a8c6ceb74cac000cd9e66d17e59ec69d1150a87cbbbb688ecb1bdfa3c7d26
data/CHANGELOG.md CHANGED
@@ -1,6 +1,13 @@
1
+ ## [v0.1.0](https://github.com/metabahn/corerb/releases/tag/2022-01-07)
2
+
3
+ *released on 2022-01-07*
4
+
5
+ * `chg` [#115](https://github.com/metabahn/corerb/pull/115) Make the loader context configurable ([bryanp](https://github.com/bryanp))
6
+ * `chg` [#114](https://github.com/metabahn/corerb/pull/114) Add an explicit strict option to loader ([bryanp](https://github.com/bryanp))
7
+
1
8
  ## [v0.0.1](https://github.com/metabahn/corerb/releases/tag/2021-11-23.1)
2
9
 
3
- *released on 2021-11-23.1*
10
+ *released on 2021-11-23*
4
11
 
5
12
  * `chg` [#109](https://github.com/metabahn/corerb/pull/109) Prefer `__send__` to `send` ([bryanp](https://github.com/bryanp))
6
13
 
@@ -9,11 +9,18 @@ module Core
9
9
  # [public]
10
10
  #
11
11
  class Context < BasicObject
12
- def initialize(path:, root:, type:, target:)
12
+ class << self
13
+ def load(path:, root:, type:, target:, strict:)
14
+ new(path: path, root: root, type: type, target: target, strict: strict).load
15
+ end
16
+ end
17
+
18
+ def initialize(path:, root:, type:, target:, strict:)
13
19
  @path = ::Kernel.Pathname(path)
14
20
  @root = ::Kernel.Pathname(root)
15
21
  @type = type.to_sym
16
22
  @target = target
23
+ @strict = strict
17
24
  end
18
25
 
19
26
  # [public]
@@ -28,7 +35,7 @@ module Core
28
35
 
29
36
  def method_missing(definable, *name, **kwargs, &block)
30
37
  if @target.makes?(definable)
31
- unless definable == @type
38
+ if @strict && definable != @type
32
39
  ::Kernel.raise "expected to define an object of type `#{@type}` but was `#{definable}` (#{@path})"
33
40
  end
34
41
 
@@ -39,7 +46,7 @@ module Core
39
46
 
40
47
  if name.empty?
41
48
  name = expected_name
42
- elsif name != expected_name
49
+ elsif @strict && name != expected_name
43
50
  ::Kernel.raise "expected to define an object named `#{expected_name.join(", ")}` but was `#{name.join(", ")}` (#{@path})"
44
51
  end
45
52
 
@@ -65,7 +72,7 @@ module Core
65
72
  end
66
73
  SOURCE
67
74
 
68
- ::Kernel.eval(eval_source, ::Kernel.const_get("TOPLEVEL_BINDING"), @path.to_s)
75
+ ::Kernel.eval(eval_source, ::Kernel.const_get(:TOPLEVEL_BINDING), @path.to_s)
69
76
  end
70
77
 
71
78
  defined
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Core
4
4
  module Loader
5
- VERSION = "0.0.1"
5
+ VERSION = "0.1.0"
6
6
 
7
7
  # [public]
8
8
  #
data/lib/is/loadable.rb CHANGED
@@ -16,7 +16,7 @@ module Is
16
16
  extends :definition do
17
17
  # [public]
18
18
  #
19
- def loads(definable, path, pattern: "*.rb")
19
+ def loads(definable, path, pattern: "*.rb", strict: true, context: Core::Loader::Context)
20
20
  unless ancestors.include?(Is::Factory) && makes?(definable)
21
21
  raise "cannot load unknown object `#{definable}`"
22
22
  end
@@ -24,7 +24,9 @@ module Is
24
24
  __loads__[definable.to_sym] = {
25
25
  type: definable,
26
26
  path: Pathname(path),
27
- pattern: pattern
27
+ pattern: pattern,
28
+ strict: strict,
29
+ context: context
28
30
  }
29
31
  end
30
32
 
@@ -39,12 +41,13 @@ module Is
39
41
 
40
42
  while (loadable_path, loadable_options = loadable.shift)
41
43
  if reload || !loaded?(loadable_path)
42
- Core::Loader::Context.new(
44
+ loadable_options[:context].load(
43
45
  path: loadable_path,
44
46
  root: loadable_options[:path],
45
47
  type: loadable_options[:type],
48
+ strict: loadable_options[:strict],
46
49
  target: self
47
- ).load
50
+ )
48
51
 
49
52
  __loaded_paths__ << loadable_path
50
53
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: core-loader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Powell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-23 00:00:00.000000000 Z
11
+ date: 2022-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: core-extension