class Mudguard::Domain::Source

Represents a Ruby source file

Constants

SYNTAX_ERROR

Public Class Methods

new(location:, code_loader: -> { "" } click to toggle source
# File lib/mudguard/domain/source.rb, line 21
def initialize(location:, code_loader: -> { "" })
  @code_loader = code_loader
  @location = location
end

Public Instance Methods

==(other) click to toggle source
# File lib/mudguard/domain/source.rb, line 26
def ==(other)
  @location == other.instance_eval { @location }
end
eql?(other) click to toggle source
# File lib/mudguard/domain/source.rb, line 34
def eql?(other)
  @location.eql?(other.instance_eval { @location })
end
find_consts() click to toggle source
# File lib/mudguard/domain/source.rb, line 48
def find_consts
  visitor = ConstVisitor.new
  visit_ast(visitor)
  visitor.consts
end
find_mod_dependencies(consts) click to toggle source
# File lib/mudguard/domain/source.rb, line 42
def find_mod_dependencies(consts)
  visitor = DependencyVisitor.new(consts: consts)
  visit_ast(visitor)
  visitor.dependencies
end
hash() click to toggle source
# File lib/mudguard/domain/source.rb, line 30
def hash
  @location.hash
end
inspect() click to toggle source
# File lib/mudguard/domain/source.rb, line 38
def inspect
  @location
end
location?(glob) click to toggle source
# File lib/mudguard/domain/source.rb, line 54
def location?(glob)
  @location == glob
end

Private Instance Methods

ast() click to toggle source
# File lib/mudguard/domain/source.rb, line 62
def ast
  @ast ||= create_ast
end
code() click to toggle source
# File lib/mudguard/domain/source.rb, line 75
def code
  @code ||= @code_loader.call
end
create_ast() click to toggle source
# File lib/mudguard/domain/source.rb, line 66
def create_ast
  begin
    root = Parser::CurrentRuby.parse(code)
  rescue Parser::SyntaxError
    return SYNTAX_ERROR
  end
  root.nil? ? SYNTAX_ERROR : root
end
visit_ast(visitor) click to toggle source
# File lib/mudguard/domain/source.rb, line 79
def visit_ast(visitor)
  return if ast == SYNTAX_ERROR

  SourceProcessor.new(location: @location).process(ast, visitor)
end