Class: Parlour::RbiGenerator::RbiObject

Inherits:
TypedObject show all
Defined in:
lib/parlour/rbi_generator/rbi_object.rb

Overview

An abstract class which is subclassed by any classes which can generate entire lines of an RBI, such as Namespace and Method. (As an example, Parameter is not a subclass because it does not generate lines, only segments of definition and signature lines.)

This class is abstract.

Direct Known Subclasses

Arbitrary, Constant, Extend, Include, Method, Namespace, TypeAlias

Instance Attribute Summary collapse

Attributes inherited from TypedObject

#comments, #generated_by, #name

Instance Method Summary collapse

Methods inherited from TypedObject

#add_comment, #describe, #describe_tree

Constructor Details

#initialize(generator, name) ⇒ void

Note:

Don’t call this directly.

Creates a new RBI object.

Parameters:

  • generator (RbiGenerator)

    The current RbiGenerator.

  • name (String)

    The name of this module.



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

def initialize(generator, name)
  super(name)
  @generator = generator
  @generated_by = RbiGenerator === generator ? generator.current_plugin : nil
end

Instance Attribute Details

#generatorGenerator (readonly)

The generator which this object belongs to.

Returns:



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

def generator
  @generator
end

Instance Method Details

#generalize_from_rbi!void

This method returns an undefined value.

Assuming that the types throughout this object and its children have been specified as RBI-style types, generalises them into type instances from the Types module.

This method is abstract.



84
# File 'lib/parlour/rbi_generator/rbi_object.rb', line 84

def generalize_from_rbi!; end

#generate_rbi(indent_level, options) ⇒ Array<String>

Generates the RBI lines for this object.

This method is abstract.

Parameters:

  • indent_level (Integer)

    The indentation level to generate the lines at.

  • options (Options)

    The formatting options to use.

Returns:

  • (Array<String>)

    The RBI lines, formatted as specified.



44
# File 'lib/parlour/rbi_generator/rbi_object.rb', line 44

def generate_rbi(indent_level, options); end

#merge_into_self(others) ⇒ void

This method returns an undefined value.

Given an array of other objects, merges them into this one. Each subclass will do this differently. You MUST ensure that #mergeable? is true for those instances.

This method is abstract.

Parameters:



74
# File 'lib/parlour/rbi_generator/rbi_object.rb', line 74

def merge_into_self(others); end

#mergeable?(others) ⇒ Boolean

Given an array of other objects, returns true if they may be merged into this instance using #merge_into_self. Each subclass will have its own criteria on what allows objects to be mergeable.

This method is abstract.

Parameters:

Returns:

  • (Boolean)

    Whether this instance may be merged with them.



59
# File 'lib/parlour/rbi_generator/rbi_object.rb', line 59

def mergeable?(others); end