Class: Parlour::RbiGenerator

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/parlour/rbi_generator.rb,
lib/parlour/rbi_generator/extend.rb,
lib/parlour/rbi_generator/method.rb,
lib/parlour/rbi_generator/include.rb,
lib/parlour/rbi_generator/options.rb,
lib/parlour/rbi_generator/constant.rb,
lib/parlour/rbi_generator/arbitrary.rb,
lib/parlour/rbi_generator/attribute.rb,
lib/parlour/rbi_generator/namespace.rb,
lib/parlour/rbi_generator/parameter.rb,
lib/parlour/rbi_generator/rbi_object.rb,
lib/parlour/rbi_generator/class_namespace.rb,
lib/parlour/rbi_generator/module_namespace.rb

Overview

The RBI generator.

Defined Under Namespace

Classes: Arbitrary, Attribute, ClassNamespace, Constant, Extend, Include, Method, ModuleNamespace, Namespace, Options, Parameter, RbiObject

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(break_params: 4, tab_size: 2) ⇒ void

Creates a new RBI generator.

Examples:

Create a default generator.

generator = Parlour::RbiGenerator.new

Create a generator with a custom tab_size of 3.

generator = Parlour::RbiGenerator.new(tab_size: 3)

Parameters:

  • break_params (Integer) (defaults to: 4)

    If there are at least this many parameters in a Sorbet sig, then it is broken onto separate lines.

  • tab_size (Integer) (defaults to: 2)

    The number of spaces to use per indent.



20
21
22
23
# File 'lib/parlour/rbi_generator.rb', line 20

def initialize(break_params: 4, tab_size: 2)
  @options = Options.new(break_params: break_params, tab_size: tab_size)
  @root = Namespace.new(self)
end

Instance Attribute Details

#current_pluginPlugin?

The plugin which is currently generating new definitions. Plugin.run_plugins controls this value.

Returns:



39
40
41
# File 'lib/parlour/rbi_generator.rb', line 39

def current_plugin
  @current_plugin
end

#optionsOptions (readonly)

The formatting options for this generator.

Returns:



28
29
30
# File 'lib/parlour/rbi_generator.rb', line 28

def options
  @options
end

#rootNamespace (readonly)

The root Namespace of this generator.

Returns:



33
34
35
# File 'lib/parlour/rbi_generator.rb', line 33

def root
  @root
end

Instance Method Details

#rbiString

Returns the complete contents of the generated RBI file as a string.

Returns:

  • (String)

    The generated RBI file



45
46
47
# File 'lib/parlour/rbi_generator.rb', line 45

def rbi
  "# typed: strong\n" + root.generate_rbi(0, options).join("\n")
end