Class: RubyLint::Definition::ConstantProxy
- Inherits:
-
Object
- Object
- RubyLint::Definition::ConstantProxy
show all
- Includes:
- VariablePredicates
- Defined in:
- lib/ruby-lint/definition/constant_proxy.rb
Overview
ConstantProxy is a proxy class for constant
definitions. The primary use case for this class is inheriting constants
in the pre-generated definitions found in the definitions directory. By
using this class when creating definitions the load order doesn’t matter,
as long as the data is there at some point in time.
Constant Summary
VariablePredicates::PREDICATE_METHODS, VariablePredicates::RUBY_CLASSES, VariablePredicates::VARIABLE_TYPES
Instance Attribute Summary collapse
Instance Method Summary
collapse
#constant?, #constant_path?, #ruby_class, #variable?
Constructor Details
#initialize(source, name, registry = nil) ⇒ ConstantProxy
Returns a new instance of ConstantProxy
38
39
40
41
42
|
# File 'lib/ruby-lint/definition/constant_proxy.rb', line 38
def initialize(source, name, registry = nil)
@proxy_source = source
@proxy_name = name
@registry = registry
end
|
Instance Attribute Details
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/ruby-lint/definition/constant_proxy.rb', line 22
class ConstantProxy
include VariablePredicates
attr_reader :proxy_source, :proxy_name, :proxy_definition, :registry
def initialize(source, name, registry = nil)
@proxy_source = source
@proxy_name = name
@registry = registry
end
RubyObject.instance_methods(false).each do |method|
define_method(method) do |*args, &block|
lookup_proxy_definition
proxy_definition.send(method, *args, &block) if proxy_definition
end
end
def inspect
lookup_proxy_definition
return proxy_definition ? proxy_definition.inspect : super
end
private
def lookup_proxy_definition
return if proxy_definition
found = lookup_constant
root = root_constant
if !found and use_registry?(root)
registry.apply(root, proxy_source)
found = lookup_constant
end
@proxy_definition = found
end
def use_registry?(constant)
return false unless registry
return true if registry.include?(constant)
registry.load(constant)
return registry.include?(constant)
end
def root_constant
return proxy_name.split(RubyObject::PATH_SEPARATOR)[0]
end
def lookup_constant
return proxy_source.lookup_constant_path(proxy_name)
end
end
|
#proxy_name ⇒ String
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/ruby-lint/definition/constant_proxy.rb', line 22
class ConstantProxy
include VariablePredicates
attr_reader :proxy_source, :proxy_name, :proxy_definition, :registry
def initialize(source, name, registry = nil)
@proxy_source = source
@proxy_name = name
@registry = registry
end
RubyObject.instance_methods(false).each do |method|
define_method(method) do |*args, &block|
lookup_proxy_definition
proxy_definition.send(method, *args, &block) if proxy_definition
end
end
def inspect
lookup_proxy_definition
return proxy_definition ? proxy_definition.inspect : super
end
private
def lookup_proxy_definition
return if proxy_definition
found = lookup_constant
root = root_constant
if !found and use_registry?(root)
registry.apply(root, proxy_source)
found = lookup_constant
end
@proxy_definition = found
end
def use_registry?(constant)
return false unless registry
return true if registry.include?(constant)
registry.load(constant)
return registry.include?(constant)
end
def root_constant
return proxy_name.split(RubyObject::PATH_SEPARATOR)[0]
end
def lookup_constant
return proxy_source.lookup_constant_path(proxy_name)
end
end
|
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/ruby-lint/definition/constant_proxy.rb', line 22
class ConstantProxy
include VariablePredicates
attr_reader :proxy_source, :proxy_name, :proxy_definition, :registry
def initialize(source, name, registry = nil)
@proxy_source = source
@proxy_name = name
@registry = registry
end
RubyObject.instance_methods(false).each do |method|
define_method(method) do |*args, &block|
lookup_proxy_definition
proxy_definition.send(method, *args, &block) if proxy_definition
end
end
def inspect
lookup_proxy_definition
return proxy_definition ? proxy_definition.inspect : super
end
private
def lookup_proxy_definition
return if proxy_definition
found = lookup_constant
root = root_constant
if !found and use_registry?(root)
registry.apply(root, proxy_source)
found = lookup_constant
end
@proxy_definition = found
end
def use_registry?(constant)
return false unless registry
return true if registry.include?(constant)
registry.load(constant)
return registry.include?(constant)
end
def root_constant
return proxy_name.split(RubyObject::PATH_SEPARATOR)[0]
end
def lookup_constant
return proxy_source.lookup_constant_path(proxy_name)
end
end
|
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/ruby-lint/definition/constant_proxy.rb', line 22
class ConstantProxy
include VariablePredicates
attr_reader :proxy_source, :proxy_name, :proxy_definition, :registry
def initialize(source, name, registry = nil)
@proxy_source = source
@proxy_name = name
@registry = registry
end
RubyObject.instance_methods(false).each do |method|
define_method(method) do |*args, &block|
lookup_proxy_definition
proxy_definition.send(method, *args, &block) if proxy_definition
end
end
def inspect
lookup_proxy_definition
return proxy_definition ? proxy_definition.inspect : super
end
private
def lookup_proxy_definition
return if proxy_definition
found = lookup_constant
root = root_constant
if !found and use_registry?(root)
registry.apply(root, proxy_source)
found = lookup_constant
end
@proxy_definition = found
end
def use_registry?(constant)
return false unless registry
return true if registry.include?(constant)
registry.load(constant)
return registry.include?(constant)
end
def root_constant
return proxy_name.split(RubyObject::PATH_SEPARATOR)[0]
end
def lookup_constant
return proxy_source.lookup_constant_path(proxy_name)
end
end
|
Instance Method Details
57
58
59
60
61
|
# File 'lib/ruby-lint/definition/constant_proxy.rb', line 57
def inspect
lookup_proxy_definition
return proxy_definition ? proxy_definition.inspect : super
end
|
108
109
110
|
# File 'lib/ruby-lint/definition/constant_proxy.rb', line 108
def lookup_constant
return proxy_source.lookup_constant_path(proxy_name)
end
|
#lookup_proxy_definition ⇒ Object
Looks up the associated definition and stores it if it exists.
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/ruby-lint/definition/constant_proxy.rb', line 68
def lookup_proxy_definition
return if proxy_definition
found = lookup_constant
root = root_constant
if !found and use_registry?(root)
registry.apply(root, proxy_source)
found = lookup_constant
end
@proxy_definition = found
end
|
#root_constant ⇒ String
101
102
103
|
# File 'lib/ruby-lint/definition/constant_proxy.rb', line 101
def root_constant
return proxy_name.split(RubyObject::PATH_SEPARATOR)[0]
end
|
#use_registry?(constant) ⇒ TrueClass|FalseClass
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/ruby-lint/definition/constant_proxy.rb', line 87
def use_registry?(constant)
return false unless registry
return true if registry.include?(constant)
registry.load(constant)
return registry.include?(constant)
end
|