class Parlour::TypedObject
A generic superclass of all objects which form part of type definitions in, specific formats, such as RbiObject and RbsObject.
Attributes
An array of comments which will be placed above the object in the RBS file. @return [Array<String>]
The {Plugin} which was controlling the {generator} when this object was created. @return [Plugin, nil]
The name of this object. @return [String]
Public Class Methods
Create a new typed object.
# File lib/parlour/typed_object.rb, line 12 def initialize(name) @name = name @comments = [] end
Public Instance Methods
Adds one or more comments to this RBS object. Comments always go above the definition for this object, not in the definition's body.
@example Creating a module with a comment.
namespace.create_module('M') do |m| m.add_comment('This is a module') end
@example 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
@param comment [String, Array<String>] The new comment(s). @return [void]
# File lib/parlour/typed_object.rb, line 50 def add_comment(comment) if comment.is_a?(String) comments << comment elsif comment.is_a?(Array) comments.concat(comment) end end
Returns a human-readable brief string description of this object. This is displayed during manual conflict resolution with the parlour
CLI.
@abstract @return [String]
# File lib/parlour/typed_object.rb, line 66 def describe; end
Protected Instance Methods
Generates the RBS lines for this object's comments.
@param indent_level [Integer] The indentation level to generate the lines at. @param options [Options] The formatting options to use. @return [Array<String>] The RBS lines for each comment, formatted as specified.
# File lib/parlour/typed_object.rb, line 81 def generate_comments(indent_level, options) comments.any? \ ? comments.map { |c| options.indented(indent_level, "# #{c}") } : [] end