Class: Lutaml::Model::Sequence
- Inherits:
-
Object
- Object
- Lutaml::Model::Sequence
- Defined in:
- lib/lutaml/model/sequence.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#model ⇒ Object
Returns the value of attribute model.
Instance Method Summary collapse
- #attribute(name, type, options = {}) ⇒ Object
-
#deep_dup(new_model = nil) ⇒ Object
Deep copy a sequence, creating independent copies of attributes The model reference is updated to point to the new parent mapping.
- #import_model_mappings(model, register = nil) ⇒ Object
-
#initialize(model, format: nil) ⇒ Sequence
constructor
A new instance of Sequence.
- #map_all ⇒ Object
- #map_attribute ⇒ Object
- #map_content ⇒ Object
- #map_element(name) ⇒ Object
- #sequence ⇒ Object
- #validate_content!(element_order, instance, register = nil) ⇒ Object
Constructor Details
#initialize(model, format: nil) ⇒ Sequence
Returns a new instance of Sequence.
9 10 11 12 13 |
# File 'lib/lutaml/model/sequence.rb', line 9 def initialize(model, format: nil) @attributes = [] @model = model @format = format end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
6 7 8 |
# File 'lib/lutaml/model/sequence.rb', line 6 def attributes @attributes end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
7 8 9 |
# File 'lib/lutaml/model/sequence.rb', line 7 def format @format end |
#model ⇒ Object
Returns the value of attribute model.
6 7 8 |
# File 'lib/lutaml/model/sequence.rb', line 6 def model @model end |
Instance Method Details
#attribute(name, type, options = {}) ⇒ Object
23 24 25 26 |
# File 'lib/lutaml/model/sequence.rb', line 23 def attribute(name, type, = {}) [:sequence] = self @model.attribute(name, type, ) end |
#deep_dup(new_model = nil) ⇒ Object
Deep copy a sequence, creating independent copies of attributes The model reference is updated to point to the new parent mapping
17 18 19 20 21 |
# File 'lib/lutaml/model/sequence.rb', line 17 def deep_dup(new_model = nil) dup_seq = Sequence.new(new_model || @model, format: @format) dup_seq.attributes = Utils.deep_dup(@attributes) dup_seq end |
#import_model_mappings(model, register = nil) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/lutaml/model/sequence.rb', line 36 def import_model_mappings(model, register = nil) if later_importable?(model) return import_mappings_later(model, register) end raise Lutaml::Model::ImportModelWithRootError.new(model) if model.root?(register) register ||= Lutaml::Model::Config.default_register # When importing a model into a sequence, we need BOTH: # 1. Object model (attributes/structure) - what data exists # 2. Serialization mappings (how to serialize) - how data maps to XML # This mimics XSD where using a complexType in a sequence means # adopting both its structure and its serialization rules # Import serialization mappings first (element names → model attributes) @model.import_model_mappings(model, register) if @format @attributes.concat(Utils.deep_dup(model.mappings_for(@format, register).elements(register))) end end |
#map_all ⇒ Object
67 68 69 |
# File 'lib/lutaml/model/sequence.rb', line 67 def map_all(*) raise Lutaml::Model::UnknownSequenceMappingError.new("map_all") end |
#map_attribute ⇒ Object
59 60 61 |
# File 'lib/lutaml/model/sequence.rb', line 59 def map_attribute(*) raise Lutaml::Model::UnknownSequenceMappingError.new("map_attribute") end |
#map_content ⇒ Object
63 64 65 |
# File 'lib/lutaml/model/sequence.rb', line 63 def map_content(*) raise Lutaml::Model::UnknownSequenceMappingError.new("map_content") end |
#map_element(name) ⇒ Object
32 33 34 |
# File 'lib/lutaml/model/sequence.rb', line 32 def map_element(name, **) @attributes << @model.map_element(name, **) end |
#sequence ⇒ Object
28 29 30 |
# File 'lib/lutaml/model/sequence.rb', line 28 def sequence(&) instance_eval(&) end |
#validate_content!(element_order, instance, register = nil) ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/lutaml/model/sequence.rb', line 71 def validate_content!(element_order, instance, register = nil) validate_sequence!( extract_defined_order(instance.class.attributes(register).transform_keys(&:to_s)), element_order, register, ) validate_child_content(instance, register) end |