Class: Renderer::Entities::Container
- Defined in:
- lib/renderer/entities/container.rb
Instance Attribute Summary collapse
-
#classes ⇒ Object
Returns the value of attribute classes.
-
#constants ⇒ Object
Returns the value of attribute constants.
-
#defined_by ⇒ Object
Returns the value of attribute defined_by.
-
#defs ⇒ Object
Returns the value of attribute defs.
-
#doc ⇒ Object
Returns the value of attribute doc.
-
#extends ⇒ Object
Returns the value of attribute extends.
-
#includes ⇒ Object
Returns the value of attribute includes.
-
#modules ⇒ Object
Returns the value of attribute modules.
-
#sdefs ⇒ Object
Returns the value of attribute sdefs.
Attributes inherited from Base
Instance Method Summary collapse
- #find_nested_container(named) ⇒ Object
- #init_entities(model, key, as:) ⇒ Object
- #init_reference(model, attr) ⇒ Object
- #init_reference!(model, attr) ⇒ Object
- #init_references!(model, key, attr: nil) ⇒ Object
-
#initialize(parent, model) ⇒ Container
constructor
A new instance of Container.
- #resolve_class_path(path) ⇒ Object
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
#classes ⇒ Object
Returns the value of attribute classes.
6 7 8 |
# File 'lib/renderer/entities/container.rb', line 6 def classes @classes end |
#constants ⇒ Object
Returns the value of attribute constants.
6 7 8 |
# File 'lib/renderer/entities/container.rb', line 6 def constants @constants end |
#defined_by ⇒ Object
Returns the value of attribute defined_by.
6 7 8 |
# File 'lib/renderer/entities/container.rb', line 6 def defined_by @defined_by end |
#defs ⇒ Object
Returns the value of attribute defs.
6 7 8 |
# File 'lib/renderer/entities/container.rb', line 6 def defs @defs end |
#doc ⇒ Object
Returns the value of attribute doc.
6 7 8 |
# File 'lib/renderer/entities/container.rb', line 6 def doc @doc end |
#extends ⇒ Object
Returns the value of attribute extends.
6 7 8 |
# File 'lib/renderer/entities/container.rb', line 6 def extends @extends end |
#includes ⇒ Object
Returns the value of attribute includes.
6 7 8 |
# File 'lib/renderer/entities/container.rb', line 6 def includes @includes end |
#modules ⇒ Object
Returns the value of attribute modules.
6 7 8 |
# File 'lib/renderer/entities/container.rb', line 6 def modules @modules end |
#sdefs ⇒ Object
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 |