class RubyLint::Definition::ConstantProxy

{RubyLint::Definition::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.

@!attribute [r] proxy_source

@return [RubyLint::Definition::RubyObject]

@!attribute [r] proxy_name

@return [String]

@!attribute [r] registry

@return [RubyLint::Definition::Registry]

@!attribute [r] proxy_definition

@return [RubyLint::Definition::RubyObject]

Attributes

proxy_definition[R]
proxy_name[R]
proxy_source[R]
registry[R]

Public Class Methods

new(source, name, registry = nil) click to toggle source

@param [RubyLint::Definition::RubyObject] source The source definition

to use for looking up the definition associated with the current
proxy.

@param [String] name The name/constant path of the constant that this

proxy belongs to.

@param [RubyLint::Registry] registry The registry to use when trying

to autoload a constant.
# 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

Public Instance Methods

inspect() click to toggle source

@return [String]

Calls superclass method
# File lib/ruby-lint/definition/constant_proxy.rb, line 57
def inspect
  lookup_proxy_definition

  return proxy_definition ? proxy_definition.inspect : super
end

Private Instance Methods

lookup_constant() click to toggle source

@return [RubyLint::Definition::RubyObject]

# 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() click to toggle source

Looks up the associated definition and stores it if it exists.

# 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() click to toggle source

@return [String]

# 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) click to toggle source

@param [String] constant @return [TrueClass|FalseClass]

# File lib/ruby-lint/definition/constant_proxy.rb, line 87
def use_registry?(constant)
  return false unless registry

  # Don't load the constant if we already have it.
  return true if registry.include?(constant)

  registry.load(constant)

  return registry.include?(constant)
end