Class: Parlour::RbiGenerator::ModuleNamespace
- Extended by:
- T::Sig
- Defined in:
- lib/parlour/rbi_generator/module_namespace.rb
Overview
Represents a module definition.
Instance Attribute Summary collapse
-
#interface ⇒ Boolean
readonly
A boolean indicating whether this module is an interface or not.
Attributes inherited from Namespace
#children, #constants, #extends, #includes
Attributes inherited from RbiObject
#comments, #generated_by, #generator, #name
Instance Method Summary collapse
-
#describe ⇒ String
Returns a human-readable brief string description of this module.
-
#generate_rbi(indent_level, options) ⇒ Array<String>
Generates the RBI lines for this module.
-
#initialize(generator, name, interface, &block) ⇒ void
constructor
Creates a new module definition.
-
#merge_into_self(others) ⇒ void
Given an array of ModuleNamespace instances, merges them into this one.
-
#mergeable?(others) ⇒ Boolean
Given an array of ModuleNamespace instances, returns true if they may be merged into this instance using #merge_into_self.
Methods inherited from Namespace
#add_comment_to_next_child, #add_constant, #add_extend, #add_include, #create_attr_accessor, #create_attr_reader, #create_attr_writer, #create_attribute, #create_class, #create_method, #create_module
Methods inherited from RbiObject
Constructor Details
#initialize(generator, name, interface, &block) ⇒ void
You should use Namespace#create_module rather than this directly.
Creates a new module definition.
25 26 27 28 29 |
# File 'lib/parlour/rbi_generator/module_namespace.rb', line 25 def initialize(generator, name, interface, &block) super(generator, name, &block) @name = name @interface = interface end |
Instance Attribute Details
#interface ⇒ Boolean (readonly)
A boolean indicating whether this module is an interface or not.
53 54 55 |
# File 'lib/parlour/rbi_generator/module_namespace.rb', line 53 def interface @interface end |
Instance Method Details
#describe ⇒ String
Returns a human-readable brief string description of this module.
91 92 93 94 |
# File 'lib/parlour/rbi_generator/module_namespace.rb', line 91 def describe "Module #{name} - #{"interface, " if interface}#{children.length} " + "children, #{includes.length} includes, #{extends.length} extends" end |
#generate_rbi(indent_level, options) ⇒ Array<String>
Generates the RBI lines for this module.
42 43 44 45 46 47 48 |
# File 'lib/parlour/rbi_generator/module_namespace.rb', line 42 def generate_rbi(indent_level, ) lines = generate_comments(indent_level, ) lines << .indented(indent_level, "module #{name}") lines += [.indented(indent_level + 1, "interface!"), ""] if interface lines += generate_body(indent_level + 1, ) lines << .indented(indent_level, "end") end |
#merge_into_self(others) ⇒ void
This method returns an undefined value.
Given an array of Parlour::RbiGenerator::ModuleNamespace instances, merges them into this one. You MUST ensure that #mergeable? is true for those instances.
84 85 86 |
# File 'lib/parlour/rbi_generator/module_namespace.rb', line 84 def merge_into_self(others) super end |
#mergeable?(others) ⇒ Boolean
Given an array of Parlour::RbiGenerator::ModuleNamespace 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.
67 68 69 70 71 72 |
# File 'lib/parlour/rbi_generator/module_namespace.rb', line 67 def mergeable?(others) others = T.cast(others, T::Array[RbiGenerator::ModuleNamespace]) rescue (return false) all = others + [self] all.map(&:interface).uniq.length == 1 end |