Class: Lap::Output

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

Instance Method Summary collapse

Constructor Details

#initialize(pathname) ⇒ Output

Returns a new instance of Output.



27
28
29
30
31
# File 'lib/lap.rb', line 27

def initialize(pathname)
  loader = RBS::EnvironmentLoader.new(core_root: nil) # don't pollute the env with ruby stdlib
  loader.add(path: Pathname(pathname))
  @env = RBS::Environment.from_loader(loader).resolve_type_names
end

Instance Method Details

#renderObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/lap.rb', line 33

def render
  output = @env.declarations.map do |decl|
    case decl
    when RBS::AST::Declarations::Class
      Lap::Class.new(decl).render
    when RBS::AST::Declarations::Module
      Lap::Module.new(decl).render
    else
      warn "TODO: #{decl} not implemented yet"
      nil
    end
  end

  puts FROZEN_STRING_COMMENT if Lap::Config[:frozen_string_literals]
  out = output.join("\n")
  puts out
  out
end