class RgGen::Core::Base::Component

Attributes

children[R]
component_index[R]
depth[R]
layer[R]
parent[R]

Public Class Methods

new(parent, base_name, layer, *args) { |self| ... } click to toggle source
# File lib/rggen/core/base/component.rb, line 7
def initialize(parent, base_name, layer, *args)
  @parent = parent
  @base_name = base_name
  @layer = layer
  @children = []
  @need_children = true
  @features = {}
  @depth = (parent&.depth || 0) + 1
  @component_index = parent&.children&.size || 0
  post_initialize(*args)
  block_given? && yield(self)
end

Public Instance Methods

add_child(child) click to toggle source
# File lib/rggen/core/base/component.rb, line 50
def add_child(child)
  need_children? && (children << child)
end
add_feature(feature) click to toggle source
# File lib/rggen/core/base/component.rb, line 54
def add_feature(feature)
  @features[feature.feature_name] = feature
end
ancestors() click to toggle source
# File lib/rggen/core/base/component.rb, line 26
def ancestors
  [].tap do |components|
    component = self
    while component
      components.unshift(component)
      component = component.parent
    end
  end
end
component_name() click to toggle source
# File lib/rggen/core/base/component.rb, line 36
def component_name
  [@layer, @base_name].compact.join('@')
end
Also aliased as: to_s
feature(key) click to toggle source
# File lib/rggen/core/base/component.rb, line 62
def feature(key)
  @features[key]
end
features() click to toggle source
# File lib/rggen/core/base/component.rb, line 58
def features
  @features.values
end
need_children?() click to toggle source
# File lib/rggen/core/base/component.rb, line 42
def need_children?
  @need_children
end
need_no_children() click to toggle source
# File lib/rggen/core/base/component.rb, line 46
def need_no_children
  @need_children = false
end
to_s()
Alias for: component_name

Private Instance Methods

define_proxy_call(receiver, method_name) click to toggle source
# File lib/rggen/core/base/component.rb, line 76
def define_proxy_call(receiver, method_name)
  (@proxy_receivers ||= {})[method_name.to_sym] = receiver
  define_singleton_method(method_name) do |*args, &block|
    name = __method__
    @proxy_receivers[name].__send__(name, *args, &block)
  end
end
define_proxy_calls(receiver, methods) click to toggle source
# File lib/rggen/core/base/component.rb, line 71
def define_proxy_calls(receiver, methods)
  Array(methods)
    .each { |method| define_proxy_call(receiver, method) }
end
post_initialize(*argv) click to toggle source
# File lib/rggen/core/base/component.rb, line 68
def post_initialize(*argv)
end