Class: Mudguard::Domain::DependencyVisitor
- Inherits:
-
Object
- Object
- Mudguard::Domain::DependencyVisitor
- Defined in:
- lib/mudguard/domain/dependency_visitor.rb
Overview
Transforms AST-Nodes into Dependencies
Instance Attribute Summary collapse
-
#dependencies ⇒ Object
readonly
Returns the value of attribute dependencies.
Instance Method Summary collapse
-
#initialize(consts:) ⇒ DependencyVisitor
constructor
A new instance of DependencyVisitor.
-
#visit_const_declaration(_, __, ___) ⇒ Object
rubocop:disable Naming/MethodParameterName.
- #visit_dependency(location, const_name, module_name) ⇒ Object
Constructor Details
#initialize(consts:) ⇒ DependencyVisitor
Returns a new instance of DependencyVisitor.
7 8 9 10 |
# File 'lib/mudguard/domain/dependency_visitor.rb', line 7 def initialize(consts:) @consts = consts @dependencies = [] end |
Instance Attribute Details
#dependencies ⇒ Object (readonly)
Returns the value of attribute dependencies.
12 13 14 |
# File 'lib/mudguard/domain/dependency_visitor.rb', line 12 def dependencies @dependencies end |
Instance Method Details
#visit_const_declaration(_, __, ___) ⇒ Object
rubocop:disable Naming/MethodParameterName
28 |
# File 'lib/mudguard/domain/dependency_visitor.rb', line 28 def visit_const_declaration(_, __, ___); end |
#visit_dependency(location, const_name, module_name) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/mudguard/domain/dependency_visitor.rb', line 14 def visit_dependency(location, const_name, module_name) qualified_const_name = @consts.resolve(module_name, const_name) return [] unless qualified_const_name&.include?("::") dependency = if module_name.empty? "->#{qualified_const_name}" else "#{module_name}->#{qualified_const_name}" end @dependencies << Dependency.new(location: location, dependency: dependency) end |