Class: ConstStricter::ConstParser

Inherits:
Object
  • Object
show all
Defined in:
lib/const_stricter/const_parser.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prism_code, file_path:) ⇒ ConstParser

Returns a new instance of ConstParser.



8
9
10
11
# File 'lib/const_stricter/const_parser.rb', line 8

def initialize(prism_code, file_path:)
  @prism_code = prism_code
  @file_path  = file_path
end

Instance Attribute Details

#file_pathObject (readonly)

Returns the value of attribute file_path.



6
7
8
# File 'lib/const_stricter/const_parser.rb', line 6

def file_path
  @file_path
end

Class Method Details

.in_code(code:) ⇒ Object



22
23
24
# File 'lib/const_stricter/const_parser.rb', line 22

def self.in_code(code:)
  new(parse_code(code), file_path: PATH_TO_MAIN).find_constants
end

.in_file(file_path:) ⇒ Object



13
14
15
# File 'lib/const_stricter/const_parser.rb', line 13

def self.in_file(file_path:)
  new(parse_file(file_path), file_path:).find_constants
end

Instance Method Details

#find_constantsObject



28
29
30
31
32
33
# File 'lib/const_stricter/const_parser.rb', line 28

def find_constants
  visitor = ScopedConstVisitor.new
  @prism_code.value[0].accept(visitor)

  find_constants_recursive(visitor.const_map)
end