Class: Parlour::RbiGenerator::Include

Inherits:
RbiObject show all
Defined in:
lib/parlour/rbi_generator/include.rb

Overview

Represents an include call.

Instance Attribute Summary

Attributes inherited from RbiObject

#generator

Attributes inherited from TypedObject

#comments, #generated_by, #name

Instance Method Summary collapse

Methods inherited from TypedObject

#add_comment, #describe, #describe_tree

Constructor Details

#initialize(generator, name: '', &block) ⇒ Include

Creates a new include call.

Parameters:

  • name (String) (defaults to: '')

    The name of the object to be included.



16
17
18
19
# File 'lib/parlour/rbi_generator/include.rb', line 16

def initialize(generator, name: '', &block)
  super(generator, name)
  yield_self(&block) if block
end

Instance Method Details

#==(other) ⇒ Boolean

Returns true if this instance is equal to another include.

Parameters:

Returns:

  • (Boolean)


27
28
29
# File 'lib/parlour/rbi_generator/include.rb', line 27

def ==(other)
  Include === other && name == other.name
end

#describe_attrsObject



82
83
84
# File 'lib/parlour/rbi_generator/include.rb', line 82

def describe_attrs
  []
end

#generalize_from_rbi!Object

Nothing to do



79
# File 'lib/parlour/rbi_generator/include.rb', line 79

def generalize_from_rbi!; end

#generate_rbi(indent_level, options) ⇒ Array<String>

Generates the RBI lines for this include.

Parameters:

  • indent_level (Integer)

    The indentation level to generate the lines at.

  • options (Options)

    The formatting options to use.

Returns:

  • (Array<String>)

    The RBI lines, formatted as specified.



42
43
44
# File 'lib/parlour/rbi_generator/include.rb', line 42

def generate_rbi(indent_level, options)
  [options.indented(indent_level, "include #{name}")]
end

#merge_into_self(others) ⇒ void

This method returns an undefined value.

Given an array of Parlour::RbiGenerator::Include 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.

Parameters:



74
75
76
# File 'lib/parlour/rbi_generator/include.rb', line 74

def merge_into_self(others)
  # We don't need to change anything! We only merge identical includes
end

#mergeable?(others) ⇒ Boolean

Given an array of Parlour::RbiGenerator::Include instances, returns true if they may be merged into this instance using #merge_into_self. This is always false.

Parameters:

Returns:

  • (Boolean)

    Whether this instance may be merged with them.



57
58
59
# File 'lib/parlour/rbi_generator/include.rb', line 57

def mergeable?(others)
  others.all? { |other| self == other }
end