import_constants 3.0.0.0.pre.1
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
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: '089352a548733dc5322214d901f387f71546aa4fb6b46be8c3f1a8d8a3080db0'
|
4
|
+
data.tar.gz: 2ede37d3b252d90f25b71580fc2c5df67c3b9e019198af983a10537eb3518da4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 279f3fbc0b60c1596b17fc4db82861c113172e7fe55b86166815efce51de6eb75915e86d7693ebee02f99c9f6e3d8078be04fb0870128f005834e8dbfe88bfa1
|
7
|
+
data.tar.gz: 755e8f5d6e0e1faa559390063335616dddaffbb2dc2123208a01df1c6ca4ec2bd815ec747446ae26d4cdfb584655b5e186d0af064f93e7866050a8e99247be09
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module ImportConstants
|
2
|
+
module Controls
|
3
|
+
module Namespace
|
4
|
+
def self.example(name: nil, &block)
|
5
|
+
Example
|
6
|
+
end
|
7
|
+
|
8
|
+
module Example
|
9
|
+
module SomeConstant
|
10
|
+
end
|
11
|
+
|
12
|
+
module SomeOtherConstant
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module Anonymous
|
17
|
+
def self.example(name: nil, &block)
|
18
|
+
name ||= self.name
|
19
|
+
|
20
|
+
namespace = Module.new
|
21
|
+
namespace.set_temporary_name(name)
|
22
|
+
|
23
|
+
if not block.nil?
|
24
|
+
namespace.module_exec(&block)
|
25
|
+
end
|
26
|
+
|
27
|
+
namespace
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.name
|
31
|
+
'Some Anonymous Module'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
module Target
|
36
|
+
def self.example(name: nil, &block)
|
37
|
+
name ||= self.name
|
38
|
+
|
39
|
+
Anonymous.example(name:)
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.name
|
43
|
+
'Some Target Module'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
module InheritNamespace
|
48
|
+
def self.example(namespace=nil)
|
49
|
+
namespace ||= Namespace.example
|
50
|
+
|
51
|
+
Anonymous.example(name:) do
|
52
|
+
include namespace
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.name
|
57
|
+
'Include Namespace'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
module AliasNamespace
|
62
|
+
def self.example(namespace=nil, name: nil)
|
63
|
+
namespace ||= Namespace.example
|
64
|
+
|
65
|
+
constant_names = namespace.constants(false)
|
66
|
+
|
67
|
+
Anonymous.example(name:) do
|
68
|
+
constant_names.each do |constant_name|
|
69
|
+
constant = namespace.const_get(constant_name)
|
70
|
+
|
71
|
+
const_set(constant_name, constant)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.name
|
77
|
+
'Alias Namespace'
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'import_constants/controls/namespace'
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module ImportConstants
|
2
|
+
Error = Class.new(RuntimeError)
|
3
|
+
|
4
|
+
def self.included(target_namespace)
|
5
|
+
target_namespace.extend(Macro)
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.call(source_namespace, target_namespace=nil, as: nil)
|
9
|
+
target_namespace ||= Object
|
10
|
+
alias_name = as
|
11
|
+
|
12
|
+
if not alias_name.nil?
|
13
|
+
if target_namespace.const_defined?(alias_name, false)
|
14
|
+
raise Error, "#{target_namespace}::#{alias_name} is already defined"
|
15
|
+
end
|
16
|
+
|
17
|
+
alias_module = Module.new
|
18
|
+
ImportConstants.(source_namespace, alias_module)
|
19
|
+
|
20
|
+
target_namespace.const_set(alias_name, alias_module)
|
21
|
+
|
22
|
+
else
|
23
|
+
inherit = false
|
24
|
+
constants = source_namespace.constants(inherit)
|
25
|
+
|
26
|
+
constants.each do |constant_name|
|
27
|
+
constant = source_namespace.const_get(constant_name)
|
28
|
+
|
29
|
+
if target_namespace.const_defined?(constant_name, false)
|
30
|
+
if warn?
|
31
|
+
warn "#{source_namespace}::#{constant_name} is not imported into #{target_namespace}. It is already defined."
|
32
|
+
end
|
33
|
+
next
|
34
|
+
end
|
35
|
+
|
36
|
+
target_namespace.const_set(constant_name, constant)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.warn?
|
42
|
+
ENV.fetch('IMPORT_CONSTANTS_WARNING', 'on') == 'on'
|
43
|
+
end
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: import_constants
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 3.0.0.0.pre.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brightworks Digital
|
8
|
+
bindir: bin
|
9
|
+
cert_chain: []
|
10
|
+
dependencies:
|
11
|
+
- !ruby/object:Gem::Dependency
|
12
|
+
name: test_bench_bootstrap
|
13
|
+
requirement: !ruby/object:Gem::Requirement
|
14
|
+
requirements:
|
15
|
+
- - ">="
|
16
|
+
- !ruby/object:Gem::Version
|
17
|
+
version: '0'
|
18
|
+
type: :development
|
19
|
+
prerelease: false
|
20
|
+
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: '0'
|
25
|
+
description: Alias all constants from one namespace into another
|
26
|
+
email: development@bright.works
|
27
|
+
executables: []
|
28
|
+
extensions: []
|
29
|
+
extra_rdoc_files: []
|
30
|
+
files:
|
31
|
+
- lib/import_constants
|
32
|
+
- lib/import_constants/controls
|
33
|
+
- lib/import_constants/controls/namespace.rb
|
34
|
+
- lib/import_constants/controls.rb
|
35
|
+
- lib/import_constants/import_constants.rb
|
36
|
+
- lib/import_constants/macro.rb
|
37
|
+
- lib/import_constants.rb
|
38
|
+
homepage: http://test-bench.software
|
39
|
+
licenses:
|
40
|
+
- MIT
|
41
|
+
metadata:
|
42
|
+
homepage_uri: http://test-bench.software
|
43
|
+
source_code_uri: https://github.com/test-bench-demo/import-constants
|
44
|
+
allowed_push_host: https://rubygems.org
|
45
|
+
namespace: ImportConstants
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubygems_version: 3.6.9
|
61
|
+
specification_version: 4
|
62
|
+
summary: Alias all constants from one namespace into another
|
63
|
+
test_files: []
|