evt-reflect 0.1.0.0 → 2.2.0.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 +4 -4
- data/lib/reflect/controls.rb +1 -0
- data/lib/reflect/controls/ancestor.rb +17 -0
- data/lib/reflect/reflect.rb +13 -10
- data/lib/reflect/reflection.rb +44 -27
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ada05571eb5a91ea63c63d8759d19d34db5d6241aa26cdfbdb2f48930e23650e
|
4
|
+
data.tar.gz: 2f98c007347876f5a4643cb736ec2f296958c5e7fa565b46f3827c0a6b319e0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a68f06bf7be25bd2dcaabc4b74c8642805586321fbe5ce390bfdce77111e3056fdaa310d5c2a5b5c34f5a6dd1a3f604f20016d357d253b184c422c11873660d
|
7
|
+
data.tar.gz: 25c76a793b5f2f7033a3a114b936b3cf19e3dd168e6a3083dae00dc2b02b81d88c419c5ac0def7afcd2d908f689058c36617edb31e37935007a572f109d658de
|
data/lib/reflect/controls.rb
CHANGED
data/lib/reflect/reflect.rb
CHANGED
@@ -1,21 +1,22 @@
|
|
1
1
|
module Reflect
|
2
2
|
Error = Class.new(RuntimeError)
|
3
3
|
|
4
|
-
def self.call(subject, constant_name, strict: nil)
|
5
|
-
Reflection.build(subject, constant_name, strict: strict)
|
4
|
+
def self.call(subject, constant_name, strict: nil, ancestors: nil)
|
5
|
+
Reflection.build(subject, constant_name, strict: strict, ancestors: ancestors)
|
6
6
|
end
|
7
7
|
|
8
|
-
def self.
|
8
|
+
def self.constant(subject)
|
9
9
|
[Module, Class].include?(subject.class) ? subject : subject.class
|
10
10
|
end
|
11
11
|
|
12
|
-
def self.get_constant(subject_constant, constant_name, strict: nil)
|
12
|
+
def self.get_constant(subject_constant, constant_name, strict: nil, ancestors: nil)
|
13
13
|
strict = Reflection::Default.strict if strict.nil?
|
14
|
+
ancestors = Reflection::Default.ancestors if ancestors.nil?
|
14
15
|
|
15
16
|
constant = nil
|
16
17
|
|
17
|
-
if constant?(subject_constant, constant_name)
|
18
|
-
constant = get_constant!(subject_constant, constant_name)
|
18
|
+
if constant?(subject_constant, constant_name, ancestors: ancestors)
|
19
|
+
constant = get_constant!(subject_constant, constant_name, ancestors: ancestors)
|
19
20
|
end
|
20
21
|
|
21
22
|
if constant.nil? && strict
|
@@ -25,11 +26,13 @@ module Reflect
|
|
25
26
|
constant
|
26
27
|
end
|
27
28
|
|
28
|
-
def self.get_constant!(subject_constant, constant_name)
|
29
|
-
|
29
|
+
def self.get_constant!(subject_constant, constant_name, ancestors: nil)
|
30
|
+
ancestors = Reflection::Default.ancestors if ancestors.nil?
|
31
|
+
subject_constant.const_get(constant_name, ancestors)
|
30
32
|
end
|
31
33
|
|
32
|
-
def self.constant?(subject_constant, constant_name)
|
33
|
-
|
34
|
+
def self.constant?(subject_constant, constant_name, ancestors: nil)
|
35
|
+
ancestors = Reflection::Default.ancestors if ancestors.nil?
|
36
|
+
subject_constant.const_defined?(constant_name, ancestors)
|
34
37
|
end
|
35
38
|
end
|
data/lib/reflect/reflection.rb
CHANGED
@@ -1,68 +1,85 @@
|
|
1
1
|
module Reflect
|
2
2
|
class Reflection
|
3
3
|
attr_reader :subject
|
4
|
-
attr_reader :
|
4
|
+
attr_reader :target
|
5
|
+
alias :constant :target
|
5
6
|
attr_reader :strict
|
6
7
|
|
7
8
|
def subject_constant
|
8
|
-
@subject_constant ||= Reflect.
|
9
|
+
@subject_constant ||= Reflect.constant(subject)
|
9
10
|
end
|
10
11
|
|
11
|
-
def initialize(subject,
|
12
|
+
def initialize(subject, target, strict)
|
12
13
|
@subject = subject
|
13
|
-
@
|
14
|
+
@target = target
|
14
15
|
@strict = strict
|
15
16
|
end
|
16
17
|
|
18
|
+
def self.build(subject, constant_name, strict: nil, ancestors: nil)
|
19
|
+
strict = Default.strict if strict.nil?
|
20
|
+
ancestors = Default.ancestors if ancestors.nil?
|
21
|
+
|
22
|
+
subject_constant = Reflect.constant(subject)
|
23
|
+
|
24
|
+
target = Reflect.get_constant(subject_constant, constant_name, strict: strict, ancestors: ancestors)
|
25
|
+
return nil if target.nil?
|
26
|
+
|
27
|
+
new(subject, target, strict)
|
28
|
+
end
|
29
|
+
|
17
30
|
def call(method_name, arg=nil)
|
18
|
-
unless
|
19
|
-
|
31
|
+
unless target.respond_to?(method_name)
|
32
|
+
target_name = Reflect.constant(target).name
|
33
|
+
raise Reflect::Error, "#{target_name} does not define method #{method_name}"
|
20
34
|
end
|
21
35
|
|
22
36
|
arg ||= subject
|
23
37
|
|
24
|
-
|
38
|
+
target.send(method_name, arg)
|
25
39
|
end
|
26
40
|
|
27
|
-
def
|
28
|
-
|
41
|
+
def target_accessor?(name, subject=nil)
|
42
|
+
subject ||= constant
|
43
|
+
subject.respond_to?(name)
|
44
|
+
end
|
29
45
|
|
30
|
-
|
46
|
+
def get(accessor_name, strict: nil, coerce_constant: nil)
|
47
|
+
strict = self.strict if strict.nil?
|
48
|
+
coerce_constant = true if coerce_constant.nil?
|
31
49
|
|
32
|
-
|
33
|
-
return nil if
|
50
|
+
target = get_target(accessor_name, strict: strict)
|
51
|
+
return nil if target.nil?
|
34
52
|
|
35
|
-
|
36
|
-
|
53
|
+
if coerce_constant
|
54
|
+
target = Reflect.constant(target)
|
55
|
+
end
|
37
56
|
|
38
|
-
|
39
|
-
constant.respond_to?(name)
|
57
|
+
self.class.new(subject, target, strict)
|
40
58
|
end
|
41
59
|
|
42
|
-
def
|
43
|
-
|
44
|
-
return nil if result.nil?
|
60
|
+
def get_target(accessor_name, strict: nil)
|
61
|
+
strict = self.strict if strict.nil?
|
45
62
|
|
46
|
-
|
47
|
-
self.class.new(subject, constant, strict)
|
48
|
-
end
|
49
|
-
|
50
|
-
def get_constant(accessor_name)
|
51
|
-
if !constant_accessor?(accessor_name)
|
63
|
+
if !target_accessor?(accessor_name)
|
52
64
|
if strict
|
53
|
-
|
65
|
+
target_name = Reflect.constant(target).name
|
66
|
+
raise Reflect::Error, "#{target_name} does not have accessor #{accessor_name}"
|
54
67
|
else
|
55
68
|
return nil
|
56
69
|
end
|
57
70
|
end
|
58
71
|
|
59
|
-
|
72
|
+
target.send(accessor_name)
|
60
73
|
end
|
61
74
|
|
62
75
|
module Default
|
63
76
|
def self.strict
|
64
77
|
true
|
65
78
|
end
|
79
|
+
|
80
|
+
def self.ancestors
|
81
|
+
false
|
82
|
+
end
|
66
83
|
end
|
67
84
|
end
|
68
85
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: evt-reflect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- The Eventide Project
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: test_bench
|
@@ -32,6 +32,7 @@ extra_rdoc_files: []
|
|
32
32
|
files:
|
33
33
|
- lib/reflect.rb
|
34
34
|
- lib/reflect/controls.rb
|
35
|
+
- lib/reflect/controls/ancestor.rb
|
35
36
|
- lib/reflect/controls/namespace.rb
|
36
37
|
- lib/reflect/controls/subject.rb
|
37
38
|
- lib/reflect/reflect.rb
|
@@ -40,7 +41,7 @@ homepage: https://github.com/eventide-project/reflect
|
|
40
41
|
licenses:
|
41
42
|
- MIT
|
42
43
|
metadata: {}
|
43
|
-
post_install_message:
|
44
|
+
post_install_message:
|
44
45
|
rdoc_options: []
|
45
46
|
require_paths:
|
46
47
|
- lib
|
@@ -55,9 +56,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
55
56
|
- !ruby/object:Gem::Version
|
56
57
|
version: '0'
|
57
58
|
requirements: []
|
58
|
-
|
59
|
-
|
60
|
-
signing_key:
|
59
|
+
rubygems_version: 3.1.2
|
60
|
+
signing_key:
|
61
61
|
specification_version: 4
|
62
62
|
summary: Reflection of inner namespaces used for protocol discovery
|
63
63
|
test_files: []
|