Class: Parlour::RbiGenerator::TypeAlias
- Inherits:
-
RbiObject
- Object
- TypedObject
- RbiObject
- Parlour::RbiGenerator::TypeAlias
- Defined in:
- lib/parlour/rbi_generator/type_alias.rb
Overview
Represents a type alias.
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Attributes inherited from RbiObject
Attributes inherited from TypedObject
#comments, #generated_by, #name
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Returns true if this instance is equal to another type alias.
- #describe_attrs ⇒ Object
- #generalize_from_rbi! ⇒ Object
-
#generate_rbi(indent_level, options) ⇒ Array<String>
Generates the RBI lines for this type alias.
-
#initialize(generator, name:, type:, &block) ⇒ TypeAlias
constructor
Creates a new type alias.
-
#merge_into_self(others) ⇒ void
Given an array of TypeAlias instances, merges them into this one.
-
#mergeable?(others) ⇒ Boolean
Given an array of TypeAlias instances, returns true if they may be merged into this instance using #merge_into_self.
Methods inherited from TypedObject
#add_comment, #describe, #describe_tree
Constructor Details
#initialize(generator, name:, type:, &block) ⇒ TypeAlias
Creates a new type alias.
18 19 20 21 22 |
# File 'lib/parlour/rbi_generator/type_alias.rb', line 18 def initialize(generator, name:, type:, &block) super(generator, name) @type = type yield_self(&block) if block end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
26 27 28 |
# File 'lib/parlour/rbi_generator/type_alias.rb', line 26 def type @type end |
Instance Method Details
#==(other) ⇒ Boolean
Returns true if this instance is equal to another type alias.
34 35 36 |
# File 'lib/parlour/rbi_generator/type_alias.rb', line 34 def ==(other) TypeAlias === other && name == other.name && type == other.type end |
#describe_attrs ⇒ Object
93 94 95 |
# File 'lib/parlour/rbi_generator/type_alias.rb', line 93 def describe_attrs [{type: type}] # avoid quotes end |
#generalize_from_rbi! ⇒ Object
88 89 90 |
# File 'lib/parlour/rbi_generator/type_alias.rb', line 88 def generalize_from_rbi! @type = TypeParser.parse_single_type(@type) if String === @type end |
#generate_rbi(indent_level, options) ⇒ Array<String>
Generates the RBI lines for this type alias.
49 50 51 52 53 |
# File 'lib/parlour/rbi_generator/type_alias.rb', line 49 def generate_rbi(indent_level, ) [.indented(indent_level, "#{name} = T.type_alias { #{String === @type ? @type : @type.generate_rbi} }" )] end |
#merge_into_self(others) ⇒ void
This method returns an undefined value.
Given an array of Parlour::RbiGenerator::TypeAlias instances, merges them into this one. This particular implementation will simply do nothing, as instances are only mergeable if they are indentical. You MUST ensure that #mergeable? is true for those instances.
83 84 85 |
# File 'lib/parlour/rbi_generator/type_alias.rb', line 83 def merge_into_self(others) # We don't need to change anything! We only merge identical type alias end |
#mergeable?(others) ⇒ Boolean
Given an array of Parlour::RbiGenerator::TypeAlias instances, returns true if they may be merged into this instance using #merge_into_self. This is always false.
66 67 68 |
# File 'lib/parlour/rbi_generator/type_alias.rb', line 66 def mergeable?(others) others.all? { |other| self == other } end |