Module: KDoc::ComposableComponents

Defined in:
lib/k_doc/mixins/composable_components.rb

Overview

Composite Design Pattern: refactoring.guru/design-patterns/composite

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#componentsObject (readonly)

Components allow downwards navigation plus access to sub-components



10
11
12
# File 'lib/k_doc/mixins/composable_components.rb', line 10

def components
  @components
end

#parentObject (readonly)

Parent allows upwards navigation to parent component



7
8
9
# File 'lib/k_doc/mixins/composable_components.rb', line 7

def parent
  @parent
end

Instance Method Details

#attach_parent(parent) ⇒ Object



12
13
14
# File 'lib/k_doc/mixins/composable_components.rb', line 12

def attach_parent(parent)
  @parent = parent
end


16
17
18
# File 'lib/k_doc/mixins/composable_components.rb', line 16

def navigate_parent
  parent.nil? ? self : parent
end

#root?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/k_doc/mixins/composable_components.rb', line 20

def root?
  parent.nil?
end