Class: RBS::Inline::Annotator::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/rbs/inline/annotator/processor.rb

Defined Under Namespace

Classes: Result

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target:, env:) ⇒ Processor

Returns a new instance of Processor.



15
16
17
18
# File 'lib/rbs/inline/annotator/processor.rb', line 15

def initialize(target:, env:)
  @target = target
  @env = env
end

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



13
14
15
# File 'lib/rbs/inline/annotator/processor.rb', line 13

def env
  @env
end

#targetObject (readonly)

Returns the value of attribute target.



13
14
15
# File 'lib/rbs/inline/annotator/processor.rb', line 13

def target
  @target
end

Instance Method Details

#processObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rbs/inline/annotator/processor.rb', line 21

def process
  absolute_path = Pathname.pwd + target
  source = absolute_path.read
  writer = Writer.new(source)
  result = Result.new(writer:, prism_result: Prism.parse_file(absolute_path.to_s))
  result.prism_result.value.accept(Visitor.new(env:, result:))
  if result.writer.actions.empty?
    [source, false]
  else
    [writer.process, true]
  end
end