evt-reflect 0.1.1.0 → 0.1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/reflect/controls.rb +1 -0
- data/lib/reflect/controls/ancestor.rb +17 -0
- data/lib/reflect/reflect.rb +12 -9
- data/lib/reflect/reflection.rb +16 -11
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a677b93e4d91b91241106755f0d2657b365f591c22c357fc21210ea66139bcd1
|
4
|
+
data.tar.gz: 25ba5a63c2120ee8ed3393c83b0a19eeffe577ec15fd88d8233cf6ae6270e1bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9a20f4f5a1b398f8562304ae67c67f8070b8c9f41bac984554079b02aedc13fde2e2c64bf6fda0454bef97cbf358b8e2b5c2df81d68fe731205f1dade0c8afc
|
7
|
+
data.tar.gz: ddce9b61efa62d27a12a041aa445e8cc4db25e617fc542a626759e6cfc98a4e7183a4b8b4ff063d9c277a87522378d2710efb4d486fd55a7cd2bc9556ca9ea51
|
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
8
|
def self.subject_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
@@ -14,6 +14,18 @@ module Reflect
|
|
14
14
|
@strict = strict
|
15
15
|
end
|
16
16
|
|
17
|
+
def self.build(subject, constant_name, strict: nil, ancestors: nil)
|
18
|
+
strict = Default.strict if strict.nil?
|
19
|
+
ancestors = Default.ancestors if ancestors.nil?
|
20
|
+
|
21
|
+
subject_constant = Reflect.subject_constant(subject)
|
22
|
+
|
23
|
+
constant = Reflect.get_constant(subject_constant, constant_name, strict: strict, ancestors: ancestors)
|
24
|
+
return nil if constant.nil?
|
25
|
+
|
26
|
+
instance = new(subject, constant, strict)
|
27
|
+
end
|
28
|
+
|
17
29
|
def call(method_name, arg=nil)
|
18
30
|
unless constant.respond_to?(method_name)
|
19
31
|
raise Reflect::Error, "Constant #{constant.name} does not define method #{method_name}"
|
@@ -24,17 +36,6 @@ module Reflect
|
|
24
36
|
constant.send(method_name, arg)
|
25
37
|
end
|
26
38
|
|
27
|
-
def self.build(subject, constant_name, strict: nil)
|
28
|
-
strict = Default.strict if strict.nil?
|
29
|
-
|
30
|
-
subject_constant = Reflect.subject_constant(subject)
|
31
|
-
|
32
|
-
constant = Reflect.get_constant(subject_constant, constant_name, strict: strict)
|
33
|
-
return nil if constant.nil?
|
34
|
-
|
35
|
-
instance = new(subject, constant, strict)
|
36
|
-
end
|
37
|
-
|
38
39
|
def constant_accessor?(name)
|
39
40
|
constant.respond_to?(name)
|
40
41
|
end
|
@@ -67,6 +68,10 @@ module Reflect
|
|
67
68
|
def self.strict
|
68
69
|
true
|
69
70
|
end
|
71
|
+
|
72
|
+
def self.ancestors
|
73
|
+
false
|
74
|
+
end
|
70
75
|
end
|
71
76
|
end
|
72
77
|
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: 0.1.
|
4
|
+
version: 0.1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- The Eventide Project
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04-
|
11
|
+
date: 2018-04-11 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
|