Class: YamlExporter::Structure
- Inherits:
-
Object
- Object
- YamlExporter::Structure
- Defined in:
- lib/yaml_exporter/structure.rb
Overview
Immutable representation of a yaml_structure do ... end block.
klass— the ActiveRecord class this structure is attached to. Resolved lazily: the constructor accepts either a class or a callable, and defers to first access. This matters for inner structures whose class might be resolved via a reflection that isn't safe to compute at declaration time (anonymous parent classes, etc.).nodes— ordered list of node objects. Order matches declaration and drives export key order.
Instance Attribute Summary collapse
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
Instance Method Summary collapse
-
#initialize(klass:, nodes:) ⇒ Structure
constructor
A new instance of Structure.
- #klass ⇒ Object
Constructor Details
#initialize(klass:, nodes:) ⇒ Structure
Returns a new instance of Structure.
16 17 18 19 |
# File 'lib/yaml_exporter/structure.rb', line 16 def initialize(klass:, nodes:) @klass_resolver = klass.respond_to?(:call) ? klass : -> { klass } @nodes = nodes end |
Instance Attribute Details
#nodes ⇒ Object (readonly)
Returns the value of attribute nodes.
14 15 16 |
# File 'lib/yaml_exporter/structure.rb', line 14 def nodes @nodes end |
Instance Method Details
#klass ⇒ Object
21 22 23 |
# File 'lib/yaml_exporter/structure.rb', line 21 def klass @klass ||= @klass_resolver.call end |