Class: Renderer::Entities::Container

Inherits:
Base show all
Defined in:
lib/renderer/entities/container.rb

Direct Known Subclasses

Class, Module

Instance Attribute Summary collapse

Attributes inherited from Base

#name, #parent, #references

Instance Method Summary collapse

Methods inherited from Base

#class?, #def?, #full_path, #inspect, #module?, #register_reference, #root, #root?, #static?, #to_s, #type

Constructor Details

#initialize(parent, model) ⇒ Container

Returns a new instance of Container.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/renderer/entities/container.rb', line 8

def initialize(parent, model)
  super(parent, model[:name])
  @classes = init_entities(model, :classes, as: Class)
  @modules = init_entities(model, :modules, as: Module)
  @extends = init_references!(model, :extends)
  @includes = init_references!(model, :includes)
  @constants = model[:constants] || {}
  @defs = model.fetch(:defs, {}).map { |k, v| Method.new(self, :def, k.to_s, v) }
  @sdefs = model.fetch(:sdefs, {}).map { |k, v| Method.new(self, :sdef, k.to_s, v) }
  @defined_by = init_entities(model, :defined_by, as: SourceDefinition)
end

Instance Attribute Details

#classesObject

Returns the value of attribute classes.



6
7
8
# File 'lib/renderer/entities/container.rb', line 6

def classes
  @classes
end

#constantsObject

Returns the value of attribute constants.



6
7
8
# File 'lib/renderer/entities/container.rb', line 6

def constants
  @constants
end

#defined_byObject

Returns the value of attribute defined_by.



6
7
8
# File 'lib/renderer/entities/container.rb', line 6

def defined_by
  @defined_by
end

#defsObject

Returns the value of attribute defs.



6
7
8
# File 'lib/renderer/entities/container.rb', line 6

def defs
  @defs
end

#docObject

Returns the value of attribute doc.



6
7
8
# File 'lib/renderer/entities/container.rb', line 6

def doc
  @doc
end

#extendsObject

Returns the value of attribute extends.



6
7
8
# File 'lib/renderer/entities/container.rb', line 6

def extends
  @extends
end

#includesObject

Returns the value of attribute includes.



6
7
8
# File 'lib/renderer/entities/container.rb', line 6

def includes
  @includes
end

#modulesObject

Returns the value of attribute modules.



6
7
8
# File 'lib/renderer/entities/container.rb', line 6

def modules
  @modules
end

#sdefsObject

Returns the value of attribute sdefs.



6
7
8
# File 'lib/renderer/entities/container.rb', line 6

def sdefs
  @sdefs
end

Instance Method Details

#find_nested_container(named) ⇒ Object



20
21
22
# File 'lib/renderer/entities/container.rb', line 20

def find_nested_container(named)
  @modules.find { _1.name == named } || @classes.find { _1.name == named }
end

#init_entities(model, key, as:) ⇒ Object



37
# File 'lib/renderer/entities/container.rb', line 37

def init_entities(model, key, as:) = model.fetch(key, []).map { as.new(self, _1) }

#init_reference(model, attr) ⇒ Object



45
46
47
48
49
# File 'lib/renderer/entities/container.rb', line 45

def init_reference(model, attr)
  return if model.nil?

  Reference.new(self, model, attr)
end

#init_reference!(model, attr) ⇒ Object



39
# File 'lib/renderer/entities/container.rb', line 39

def init_reference!(model, attr) = Reference.new(self, model, attr)

#init_references!(model, key, attr: nil) ⇒ Object



41
42
43
# File 'lib/renderer/entities/container.rb', line 41

def init_references!(model, key, attr: nil)
  model.fetch(key, []).map { init_reference!(_1, attr || key) }
end

#resolve_class_path(path) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/renderer/entities/container.rb', line 24

def resolve_class_path(path)
  path.shift if path.first == "::"
  obj = find_nested_container(path.shift)
  return if obj.nil?

  until path.empty?
    obj = obj.find_nested_container(path.shift)
    return if obj.nil?
  end

  obj
end