Class: RubyLint::DefinitionBuilder::RubyModule

Inherits:
Base
  • Object
show all
Defined in:
lib/ruby-lint/definition_builder/ruby_module.rb

Overview

Definition builder used for building Ruby modules as well as providing the groundwork for building Ruby classes.

Direct Known Subclasses

RubyClass

Instance Attribute Summary

Attributes inherited from Base

#node, #options, #vm

Instance Method Summary collapse

Methods inherited from Base

#constant_name, #initialize

Constructor Details

This class inherits a constructor from RubyLint::DefinitionBuilder::Base

Instance Method Details

#buildObject

Creates a new module definition.

See Also:



13
14
15
16
17
# File 'lib/ruby-lint/definition_builder/ruby_module.rb', line 13

def build
  mod = vm.global_constant('Module')

  return new_definition([mod, vm.current_scope])
end

#module_nameObject (protected)

Returns the name of the module.

See Also:



45
46
47
# File 'lib/ruby-lint/definition_builder/ruby_module.rb', line 45

def module_name
  return constant_name(node.children[0])
end

#new_definition(parents) ⇒ RubyLint::Definition::RubyObject (protected)

Creates a new RubyObject definition with the specified parent definitions.

Parameters:

  • parents (Array)

Returns:



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/ruby-lint/definition_builder/ruby_module.rb', line 56

def new_definition(parents)
  definition = Definition::RubyObject.new(
    :name             => module_name,
    :parents          => parents,
    :reference_amount => 1,
    :type             => :const,
    :line             => node.line,
    :column           => node.column,
    :file             => node.file
  )

  definition.define_self

  return definition
end

#scopeRubyLint::Definition::RubyObject

Determines the scope to define the module in.



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ruby-lint/definition_builder/ruby_module.rb', line 24

def scope
  scope       = vm.current_scope
  name_prefix = node.children[0].children[0]

  # name_prefix contains the constant path leading up to the name. For
  # example, if the name is `A::B::C` this node would contain `A::B`.
  if name_prefix
    found = ConstantPath.new(name_prefix).resolve(vm.current_scope)
    scope = found if found
  end

  return scope
end