class Parlour::RbiGenerator::ModuleNamespace
Represents a module definition.
Attributes
A boolean indicating whether this module is abstract or not. @return [Boolean]
A boolean indicating whether this module is an interface or not. @return [Boolean]
Public Class Methods
Creates a new module definition. @note You should use {Namespace#create_module} rather than this directly.
@param generator [RbiGenerator] The current RbiGenerator
. @param name [String] The name of this module. @param final [Boolean] Whether this namespace is final. @param sealed [Boolean] Whether this namespace is sealed. @param interface [Boolean] A boolean indicating whether this module is an
interface.
@param abstract [Boolean] A boolean indicating whether this module is abstract. @param block A block which the new instance yields itself to. @return [void]
# File lib/parlour/rbi_generator/module_namespace.rb, line 31 def initialize(generator, name, final, sealed, interface, abstract, &block) super(generator, name, final, sealed, &block) @name = name @interface = interface @abstract = abstract end
Public Instance Methods
Returns a human-readable brief string description of this module. @return [String]
# File lib/parlour/rbi_generator/module_namespace.rb, line 106 def describe "Module #{name} - #{"interface, " if interface}" + "#{"abstract, " if abstract}#{children.length} " + "children, #{includes.length} includes, #{extends.length} extends" end
# File lib/parlour/rbi_generator/module_namespace.rb, line 113 def generalize_from_rbi! super end
Generates the RBI lines for this module.
@param indent_level [Integer] The indentation level to generate the lines at. @param options [Options] The formatting options to use. @return [Array<String>] The RBI lines, formatted as specified.
# File lib/parlour/rbi_generator/module_namespace.rb, line 49 def generate_rbi(indent_level, options) lines = generate_comments(indent_level, options) lines << options.indented(indent_level, "module #{name}") lines += [options.indented(indent_level + 1, "interface!"), ""] if interface lines += [options.indented(indent_level + 1, "abstract!"), ""] if abstract lines += generate_body(indent_level + 1, options) lines << options.indented(indent_level, "end") end
Given an array of {ModuleNamespace} instances, merges them into this one. You MUST ensure that {mergeable?} is true for those instances.
@param others [Array<RbiGenerator::RbiObject>] An array of other {ModuleNamespace} instances. @return [void]
# File lib/parlour/rbi_generator/module_namespace.rb, line 99 def merge_into_self(others) super end
Given an array of {Namespace} instances, returns true if they may be merged into this instance using {merge_into_self}. For instances to be mergeable, they must either all be interfaces or all not be interfaces.
@param others [Array<RbiGenerator::RbiObject>] An array of other {Namespace} instances. @return [Boolean] Whether this instance may be merged with them.
# File lib/parlour/rbi_generator/module_namespace.rb, line 80 def mergeable?(others) others = T.cast(others, T::Array[Namespace]) rescue (return false) all = others + [self] all_modules = T.cast(all.select { |x| ModuleNamespace === x }, T::Array[ModuleNamespace]) all_modules.map(&:interface).uniq.length == 1 end