evt-constant 2.2.0.0 → 2.2.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: 7b012e976058289cb87180483efb47e51d2f9f510e6089ec32f8ea12aaa2245b
4
- data.tar.gz: 5a50636f4f77c8a5aa4920178a66749221fbce806440fa4958367bce3185ed82
3
+ metadata.gz: ff234cd73757812512933c025d3b6145ec09d50c86638db927ca5000feee1f6c
4
+ data.tar.gz: 89749a6d6d39f569b37e3a9ed092565c516a76c0e1fe34431b8efd551f4db096
5
5
  SHA512:
6
- metadata.gz: a5c0b2b1c190b528c213a38ea920fbd786a7d588ccc922987baba6a7e8fd1ddacfcea0075e339b0bd6be1c3cbf29d783a56a88b023d4e76916681982ad494e23
7
- data.tar.gz: 11fae6756c40334c83284d299c7f5e6370d0f77ceff1965896b8849c5394eba4e16f70f0850c5f5ac4b3a627d136a35e168ad4b32c2f9edf56e29b28b4631c5d
6
+ metadata.gz: f92b015b8fcbe17dd1ea04aa55f2855754882a1d951a95f3939728b76946a684de6236a35d45caed723247f2475aa9d4b0d131f6de464c225b17277d7937edef
7
+ data.tar.gz: 10ffaabb126ff50093b231337ff3e77b0295b028e1ca40a9bd6a4282c8768a386adf019b2644d0e2d0aa43cd268bb56531920574b1f27cf4f49a5dce6bcf8a99
@@ -3,8 +3,8 @@ require "open3"
3
3
  module Constant
4
4
  module Controls
5
5
  module Script
6
- def self.top_level_import(origin_name: nil, inner_constants: nil)
7
- origin_name ||= "SomeOrigin"
6
+ def self.top_level_import(source_name: nil, inner_constants: nil)
7
+ source_name ||= "SomeSource"
8
8
  inner_constants ||= ["SomeInnerConstant"]
9
9
 
10
10
  inner_constant_definitions = inner_constants.map do |inner_constant_name|
@@ -21,13 +21,13 @@ module Constant
21
21
  source = <<~RUBY
22
22
  require "constant"
23
23
 
24
- module #{origin_name}
24
+ module #{source_name}
25
25
  #{definitions}
26
26
  end
27
27
 
28
28
  include Constant::Import
29
29
 
30
- import #{origin_name}
30
+ import #{source_name}
31
31
 
32
32
  #{resolutions}
33
33
  RUBY
@@ -35,8 +35,8 @@ module Constant
35
35
  Example.new(source)
36
36
  end
37
37
 
38
- def self.top_level_refinement_import(origin_name: nil, inner_constants: nil)
39
- origin_name ||= "SomeOrigin"
38
+ def self.top_level_refinement_import(source_name: nil, inner_constants: nil)
39
+ source_name ||= "SomeSource"
40
40
  inner_constants ||= ["SomeInnerConstant"]
41
41
 
42
42
  inner_constant_definitions = inner_constants.map do |inner_constant_name|
@@ -53,13 +53,13 @@ module Constant
53
53
  source = <<~RUBY
54
54
  require "constant"
55
55
 
56
- module #{origin_name}
56
+ module #{source_name}
57
57
  #{definitions}
58
58
  end
59
59
 
60
60
  using Constant::Import
61
61
 
62
- import #{origin_name}
62
+ import #{source_name}
63
63
 
64
64
  #{resolutions}
65
65
  RUBY
@@ -16,7 +16,9 @@ module Constant
16
16
  alias import __import_constant
17
17
  end
18
18
 
19
- def self.call(origin_constant, destination_constant, **kwargs)
19
+ def self.call(origin_constant, destination_constant, only: nil, except: nil, override_ancestor: nil, **kwargs)
20
+ override_ancestor ||= false
21
+
20
22
  if not destination_constant.is_a?(::Module)
21
23
  destination_constant = destination_constant.class
22
24
  end
@@ -37,6 +39,54 @@ module Constant
37
39
 
38
40
  import_constant_names = origin_constant.constants(inherit)
39
41
 
42
+ only_constant_names = Array(only)
43
+ only_constant_names = only_constant_names.map { |only_constant_name| only_constant_name.to_sym }
44
+
45
+ except_constant_names = Array(except)
46
+ except_constant_names = except_constant_names.map { |except_constant_name| except_constant_name.to_sym }
47
+
48
+ conflicting_constant_names = only_constant_names & except_constant_names
49
+
50
+ if conflicting_constant_names.any?
51
+ conflicting_constant_name = conflicting_constant_names.first
52
+ raise Constant::Error, "#{conflicting_constant_name} is named in both only: and except:"
53
+ end
54
+
55
+ if only_constant_names.any?
56
+ undefined_constant_names = only_constant_names - import_constant_names
57
+
58
+ if undefined_constant_names.any?
59
+ undefined_constant_name = undefined_constant_names.first
60
+ raise Constant::Error, "#{undefined_constant_name} is not defined on #{origin_constant}"
61
+ end
62
+
63
+ import_constant_names = import_constant_names & only_constant_names
64
+ end
65
+
66
+ import_constant_names = import_constant_names - except_constant_names
67
+
68
+ if override_ancestor
69
+ collision_constants = [target]
70
+ else
71
+ collision_constants = target.ancestors
72
+ end
73
+
74
+ import_constant_names.each do |import_constant_name|
75
+ defining_constant = collision_constants.find do |collision_constant|
76
+ collision_constant.const_defined?(import_constant_name, false)
77
+ end
78
+
79
+ if defining_constant.nil?
80
+ next
81
+ end
82
+
83
+ if defining_constant.equal?(target)
84
+ raise Constant::Error, "#{import_constant_name} is already defined on #{target} (imported from #{origin_constant})"
85
+ end
86
+
87
+ raise Constant::Error, "#{import_constant_name} is inherited by #{target} from #{defining_constant} (imported from #{origin_constant})"
88
+ end
89
+
40
90
  imported_constants = import_constant_names.map do |import_constant_name|
41
91
  import_constant = origin_constant.const_get(import_constant_name, inherit)
42
92
  target.const_set(import_constant_name, import_constant)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evt-constant
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0.0
4
+ version: 2.2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Eventide Project