Class: Parlour::RbiGenerator::ModuleNamespace
- Inherits:
-
Namespace
- Object
- TypedObject
- RbiObject
- Namespace
- Parlour::RbiGenerator::ModuleNamespace
- Extended by:
- T::Sig
- Defined in:
- lib/parlour/rbi_generator/module_namespace.rb
Overview
Represents a module definition.
Constant Summary collapse
- Child =
type_member {{ fixed: RbiObject }}
Instance Attribute Summary collapse
-
#abstract ⇒ Boolean
readonly
A boolean indicating whether this module is abstract or not.
-
#interface ⇒ Boolean
readonly
A boolean indicating whether this module is an interface or not.
Attributes inherited from Namespace
Attributes inherited from RbiObject
Attributes inherited from TypedObject
#comments, #generated_by, #name
Instance Method Summary collapse
- #describe_attrs ⇒ Object
- #generalize_from_rbi! ⇒ Object
-
#generate_rbi(indent_level, options) ⇒ Array<String>
Generates the RBI lines for this module.
-
#initialize(generator, name, final, sealed, interface, abstract, &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, #aliases, #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 included from Mixin::Searchable
Methods inherited from TypedObject
#add_comment, #describe, #describe_tree
Constructor Details
#initialize(generator, name, final, sealed, interface, abstract, &block) ⇒ void
You should use Namespace#create_module rather than this directly.
Creates a new module definition.
33 34 35 36 37 38 |
# File 'lib/parlour/rbi_generator/module_namespace.rb', line 33 def initialize(generator, name, final, sealed, interface, abstract, &block) super(generator, name, final, sealed, &T.cast(block, T.nilable(T.proc.params(x: Namespace).void))) @name = name @interface = interface @abstract = abstract end |
Instance Attribute Details
#abstract ⇒ Boolean (readonly)
A boolean indicating whether this module is abstract or not.
68 69 70 |
# File 'lib/parlour/rbi_generator/module_namespace.rb', line 68 def abstract @abstract end |
#interface ⇒ Boolean (readonly)
A boolean indicating whether this module is an interface or not.
63 64 65 |
# File 'lib/parlour/rbi_generator/module_namespace.rb', line 63 def interface @interface end |
Instance Method Details
#describe_attrs ⇒ Object
111 112 113 |
# File 'lib/parlour/rbi_generator/module_namespace.rb', line 111 def describe_attrs [:children, :abstract, :interface, :final, :sealed] end |
#generalize_from_rbi! ⇒ Object
106 107 108 |
# File 'lib/parlour/rbi_generator/module_namespace.rb', line 106 def generalize_from_rbi! super end |
#generate_rbi(indent_level, options) ⇒ Array<String>
Generates the RBI lines for this module.
51 52 53 54 55 56 57 58 |
# File 'lib/parlour/rbi_generator/module_namespace.rb', line 51 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 += [.indented(indent_level + 1, "abstract!"), ""] if abstract 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.
101 102 103 |
# File 'lib/parlour/rbi_generator/module_namespace.rb', line 101 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.
82 83 84 85 86 87 88 89 |
# File 'lib/parlour/rbi_generator/module_namespace.rb', line 82 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 |