evt-reflect 0.1.2.0 → 0.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/reflect/reflect.rb +1 -1
- data/lib/reflect/reflection.rb +30 -22
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 123bd228ca91520f866f3bc1e14b4a0393faa1ab9ed42e13ec10e2eb489fd753
|
4
|
+
data.tar.gz: 1f835ab7273697e2a5449a438b163f0d2fa54332dc565bbead69533b3ae9084c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e04997ea94f314b8d25933445474b72cca7a63efc73f9c0d81cc885bc75bc558e2a0fbbe4b7eadb4f86e452d3d9e01535c12cdcdc0dce70e5ddafc33c9985acb
|
7
|
+
data.tar.gz: 6d2291e4f14037d41433fcd15ea64b3d419d785e542f1fd658395714090393d36ebba39dc4938e28c52d4b4cce66494f0681a2b74a926b6b3abfa464b30d7c8b
|
data/lib/reflect/reflect.rb
CHANGED
data/lib/reflect/reflection.rb
CHANGED
@@ -1,16 +1,17 @@
|
|
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,50 +19,57 @@ module Reflect
|
|
18
19
|
strict = Default.strict if strict.nil?
|
19
20
|
ancestors = Default.ancestors if ancestors.nil?
|
20
21
|
|
21
|
-
subject_constant = Reflect.
|
22
|
+
subject_constant = Reflect.constant(subject)
|
22
23
|
|
23
|
-
|
24
|
-
return nil if
|
24
|
+
target = Reflect.get_constant(subject_constant, constant_name, strict: strict, ancestors: ancestors)
|
25
|
+
return nil if target.nil?
|
25
26
|
|
26
|
-
instance = new(subject,
|
27
|
+
instance = new(subject, target, strict)
|
27
28
|
end
|
28
29
|
|
29
30
|
def call(method_name, arg=nil)
|
30
|
-
unless
|
31
|
-
|
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}"
|
32
34
|
end
|
33
35
|
|
34
36
|
arg ||= subject
|
35
37
|
|
36
|
-
|
38
|
+
target.send(method_name, arg)
|
37
39
|
end
|
38
40
|
|
39
|
-
def
|
40
|
-
constant
|
41
|
+
def target_accessor?(name, subject=nil)
|
42
|
+
subject ||= constant
|
43
|
+
subject.respond_to?(name)
|
41
44
|
end
|
42
45
|
|
43
|
-
def get(accessor_name, strict: nil)
|
46
|
+
def get(accessor_name, strict: nil, coerce_constant: nil)
|
44
47
|
strict = self.strict if strict.nil?
|
48
|
+
coerce_constant = true if coerce_constant.nil?
|
45
49
|
|
46
|
-
|
47
|
-
return nil if
|
50
|
+
target = get_target(accessor_name, strict: strict)
|
51
|
+
return nil if target.nil?
|
48
52
|
|
49
|
-
|
50
|
-
|
53
|
+
if coerce_constant
|
54
|
+
target = Reflect.constant(target)
|
55
|
+
end
|
56
|
+
|
57
|
+
self.class.new(subject, target, strict)
|
51
58
|
end
|
52
59
|
|
53
|
-
def
|
60
|
+
def get_target(accessor_name, strict: nil)
|
54
61
|
strict = self.strict if strict.nil?
|
55
62
|
|
56
|
-
if !
|
63
|
+
if !target_accessor?(accessor_name)
|
57
64
|
if strict
|
58
|
-
|
65
|
+
target_name = Reflect.constant(target).name
|
66
|
+
raise Reflect::Error, "#{target_name} does not have accessor #{accessor_name}"
|
59
67
|
else
|
60
68
|
return nil
|
61
69
|
end
|
62
70
|
end
|
63
71
|
|
64
|
-
|
72
|
+
target.send(accessor_name)
|
65
73
|
end
|
66
74
|
|
67
75
|
module Default
|
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.
|
4
|
+
version: 0.2.0.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-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: test_bench
|