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
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, final, 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 Namespace instances, returns true if they may be merged into this instance using #merge_into_self.
Methods inherited from Namespace
#add_comment_to_next_child, #constants, #create_arbitrary, #create_attr_accessor, #create_attr_reader, #create_attr_writer, #create_attribute, #create_class, #create_constant, #create_enum_class, #create_extend, #create_extends, #create_include, #create_includes, #create_method, #create_module, #create_struct_class, #create_type_alias, #extends, #includes, #path
Methods inherited from RbiObject
Constructor Details
#initialize(generator, name, final, interface, &block) ⇒ void
You should use Namespace#create_module rather than this directly.
Creates a new module definition.
27 28 29 30 31 |
# File 'lib/parlour/rbi_generator/module_namespace.rb', line 27 def initialize(generator, name, final, interface, &block) super(generator, name, final, &block) @name = name @interface = interface end |
Instance Attribute Details
#interface ⇒ Boolean (readonly)
A boolean indicating whether this module is an interface or not.
55 56 57 |
# File 'lib/parlour/rbi_generator/module_namespace.rb', line 55 def interface @interface end |
Instance Method Details
#describe ⇒ String
Returns a human-readable brief string description of this module.
95 96 97 98 |
# File 'lib/parlour/rbi_generator/module_namespace.rb', line 95 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.
44 45 46 47 48 49 50 |
# File 'lib/parlour/rbi_generator/module_namespace.rb', line 44 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.
88 89 90 |
# File 'lib/parlour/rbi_generator/module_namespace.rb', line 88 def merge_into_self(others) super end |
#mergeable?(others) ⇒ Boolean
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.
69 70 71 72 73 74 75 76 |
# File 'lib/parlour/rbi_generator/module_namespace.rb', line 69 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 |