evt-constant 2.1.1.0 → 2.2.0.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/constant/controls/script.rb +53 -7
- data/lib/constant/import/macro.rb +3 -7
- data/lib/constant/import.rb +14 -2
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7b012e976058289cb87180483efb47e51d2f9f510e6089ec32f8ea12aaa2245b
|
|
4
|
+
data.tar.gz: 5a50636f4f77c8a5aa4920178a66749221fbce806440fa4958367bce3185ed82
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a5c0b2b1c190b528c213a38ea920fbd786a7d588ccc922987baba6a7e8fd1ddacfcea0075e339b0bd6be1c3cbf29d783a56a88b023d4e76916681982ad494e23
|
|
7
|
+
data.tar.gz: 11fae6756c40334c83284d299c7f5e6370d0f77ceff1965896b8849c5394eba4e16f70f0850c5f5ac4b3a627d136a35e168ad4b32c2f9edf56e29b28b4631c5d
|
|
@@ -35,19 +35,45 @@ 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"
|
|
40
|
+
inner_constants ||= ["SomeInnerConstant"]
|
|
41
|
+
|
|
42
|
+
inner_constant_definitions = inner_constants.map do |inner_constant_name|
|
|
43
|
+
"#{inner_constant_name} = ::Module.new"
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
inner_constant_resolutions = inner_constants.map do |inner_constant_name|
|
|
47
|
+
"puts #{inner_constant_name}.name"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
definitions = inner_constant_definitions.join("\n")
|
|
51
|
+
resolutions = inner_constant_resolutions.join("\n")
|
|
52
|
+
|
|
53
|
+
source = <<~RUBY
|
|
54
|
+
require "constant"
|
|
55
|
+
|
|
56
|
+
module #{origin_name}
|
|
57
|
+
#{definitions}
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
using Constant::Import
|
|
61
|
+
|
|
62
|
+
import #{origin_name}
|
|
63
|
+
|
|
64
|
+
#{resolutions}
|
|
65
|
+
RUBY
|
|
66
|
+
|
|
67
|
+
Example.new(source)
|
|
68
|
+
end
|
|
69
|
+
|
|
38
70
|
class Example
|
|
39
71
|
include Initializer
|
|
40
72
|
|
|
41
73
|
initializer :source
|
|
42
74
|
|
|
43
75
|
def run
|
|
44
|
-
|
|
45
|
-
"-I#{load_path_entry}"
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
command = ["ruby", *load_path_options, "-e", source]
|
|
49
|
-
|
|
50
|
-
output, error_output, status = Open3.capture3(*command)
|
|
76
|
+
output, error_output, status = execute
|
|
51
77
|
|
|
52
78
|
if not status.success?
|
|
53
79
|
raise "Script failed\n\n#{source}\n#{error_output}"
|
|
@@ -55,6 +81,26 @@ module Constant
|
|
|
55
81
|
|
|
56
82
|
output.split("\n")
|
|
57
83
|
end
|
|
84
|
+
|
|
85
|
+
def error
|
|
86
|
+
_, error_output, status = execute
|
|
87
|
+
|
|
88
|
+
if status.success?
|
|
89
|
+
raise "Script succeeded\n\n#{source}"
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
error_output
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def execute
|
|
96
|
+
load_path_options = $LOAD_PATH.map do |load_path_entry|
|
|
97
|
+
"-I#{load_path_entry}"
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
command = ["ruby", *load_path_options, "-e", source]
|
|
101
|
+
|
|
102
|
+
Open3.capture3(*command)
|
|
103
|
+
end
|
|
58
104
|
end
|
|
59
105
|
end
|
|
60
106
|
end
|
|
@@ -2,16 +2,12 @@ module Constant
|
|
|
2
2
|
module Import
|
|
3
3
|
module Macro
|
|
4
4
|
def __import_constant(origin_constant, **kwargs)
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
if not destination.is_a?(::Module)
|
|
8
|
-
destination = destination.class
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
Import.(origin_constant, destination, **kwargs)
|
|
5
|
+
Import.(origin_constant, self, **kwargs)
|
|
12
6
|
end
|
|
13
7
|
|
|
14
8
|
alias import __import_constant
|
|
15
9
|
end
|
|
10
|
+
|
|
11
|
+
private_constant :Macro
|
|
16
12
|
end
|
|
17
13
|
end
|
data/lib/constant/import.rb
CHANGED
|
@@ -1,14 +1,26 @@
|
|
|
1
1
|
module Constant
|
|
2
2
|
module Import
|
|
3
3
|
def self.included(base)
|
|
4
|
+
if base.equal?(::Object)
|
|
5
|
+
raise Constant::Error, "Constant::Import cannot be included at the top level, where the destination is Object. Activate the refinement instead: using Constant::Import"
|
|
6
|
+
end
|
|
7
|
+
|
|
4
8
|
base.extend(Macro)
|
|
9
|
+
end
|
|
5
10
|
|
|
6
|
-
|
|
7
|
-
|
|
11
|
+
refine ::Object do
|
|
12
|
+
def __import_constant(origin_constant, **kwargs)
|
|
13
|
+
Import.(origin_constant, self, **kwargs)
|
|
8
14
|
end
|
|
15
|
+
|
|
16
|
+
alias import __import_constant
|
|
9
17
|
end
|
|
10
18
|
|
|
11
19
|
def self.call(origin_constant, destination_constant, **kwargs)
|
|
20
|
+
if not destination_constant.is_a?(::Module)
|
|
21
|
+
destination_constant = destination_constant.class
|
|
22
|
+
end
|
|
23
|
+
|
|
12
24
|
alias_name = kwargs[:alias]
|
|
13
25
|
|
|
14
26
|
if alias_name.nil? && destination_constant.ancestors.include?(origin_constant)
|