Class: Parlour::RbiGenerator::RbiObject Abstract

Inherits:
Object
  • Object
show all
Extended by:
T::Helpers, T::Sig
Defined in:
lib/parlour/rbi_generator/rbi_object.rb

Overview

This class is abstract.

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.)

Direct Known Subclasses

Arbitrary, Constant, Extend, Include, Method, Namespace

Instance Attribute Summary collapse

Instance Method Summary collapse

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.



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

def initialize(generator, name)
  @generator = generator
  @generated_by = generator.current_plugin
  @name = name
  @comments = []
end

Instance Attribute Details

#commentsArray<String> (readonly)

An array of comments which will be placed above the object in the RBI file.

Returns:

  • (Array<String>)


48
49
50
# File 'lib/parlour/rbi_generator/rbi_object.rb', line 48

def comments
  @comments
end

#generated_byPlugin? (readonly)

The Plugin which was controlling the #generator when this object was created.

Returns:



37
38
39
# File 'lib/parlour/rbi_generator/rbi_object.rb', line 37

def generated_by
  @generated_by
end

#generatorRbiGenerator (readonly)

The generator which this object belongs to.

Returns:



31
32
33
# File 'lib/parlour/rbi_generator/rbi_object.rb', line 31

def generator
  @generator
end

#nameString (readonly)

The name of this object.

Returns:

  • (String)


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

def name
  @name
end

Instance Method Details

#add_comment(comment) ⇒ void Also known as: add_comments

This method returns an undefined value.

Adds one or more comments to this RBI object. Comments always go above the definition for this object, not in the definition’s body.

Examples:

Creating a module with a comment.

namespace.create_module('M') do |m|
  m.add_comment('This is a module')
end

Creating a class with a multi-line comment.

namespace.create_class('C') do |c|
  c.add_comment(['This is a multi-line comment!', 'It can be as long as you want!'])
end

Parameters:

  • comment (String, Array<String>)

    The new comment(s).



66
67
68
69
70
71
72
# File 'lib/parlour/rbi_generator/rbi_object.rb', line 66

def add_comment(comment)
  if comment.is_a?(String)
    comments << comment
  elsif comment.is_a?(Array)
    comments.concat(comment)
  end
end

#describeString

This method is abstract.

Returns a human-readable brief string description of this object. This is displayed during manual conflict resolution with the parlour CLI.

Returns:

  • (String)


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

def describe; end

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

This method is abstract.

Generates the RBI lines for this object.

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.



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

def generate_rbi(indent_level, options); end

#merge_into_self(others) ⇒ void

This method is abstract.

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.

Parameters:



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

def merge_into_self(others); end

#mergeable?(others) ⇒ Boolean

This method is abstract.

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.

Parameters:

Returns:

  • (Boolean)

    Whether this instance may be merged with them.



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

def mergeable?(others); end