Class: Lutaml::Model::KeyValueMappingRule

Inherits:
MappingRule
  • Object
show all
Defined in:
lib/lutaml/model/mapping/key_value_mapping_rule.rb

Constant Summary

Constants inherited from MappingRule

MappingRule::ALLOWED_OPTIONS

Instance Attribute Summary collapse

Attributes inherited from MappingRule

#as_attribute, #attribute, #custom_methods, #delegate, #format, #name, #polymorphic, #polymorphic_map, #render_default, #render_empty, #render_nil, #to, #to_instance, #transform, #treat_empty, #treat_nil, #treat_omitted

Instance Method Summary collapse

Methods inherited from MappingRule

#default_value_map, #deserialize, #eql?, #has_custom_method_for_deserialization?, #has_custom_method_for_serialization?, #multiple_mappings?, #polymorphic_mapping?, #raw_mapping?, #render?, #render_as, #render_empty?, #render_nil?, #render_omitted?, #render_value_for, #serialize, #serialize_attribute, #to_value_for, #treat?, #treat_as, #treat_empty?, #treat_nil?, #treat_omitted?, #value_for_option, #value_map

Constructor Details

#initialize(name, to:, to_instance: nil, as_attribute: nil, render_nil: false, render_default: false, render_empty: false, treat_nil: :nil, treat_empty: :empty, treat_omitted: :nil, with: {}, delegate: nil, child_mappings: nil, root_mappings: nil, polymorphic: {}, polymorphic_map: {}, transform: {}, value_map: {}) ⇒ KeyValueMappingRule

Returns a new instance of KeyValueMappingRule.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/lutaml/model/mapping/key_value_mapping_rule.rb', line 9

def initialize(
  name,
  to:,
  to_instance: nil,
  as_attribute: nil,
  render_nil: false,
  render_default: false,
  render_empty: false,
  treat_nil: :nil,
  treat_empty: :empty,
  treat_omitted: :nil,
  with: {},
  delegate: nil,
  child_mappings: nil,
  root_mappings: nil,
  polymorphic: {},
  polymorphic_map: {},
  transform: {},
  value_map: {}
)
  super(
    name,
    to: to,
    to_instance: to_instance,
    as_attribute: as_attribute,
    render_nil: render_nil,
    render_default: render_default,
    render_empty: render_empty,
    treat_nil: treat_nil,
    treat_empty: treat_empty,
    treat_omitted: treat_omitted,
    with: with,
    delegate: delegate,
    polymorphic: polymorphic,
    polymorphic_map: polymorphic_map,
    transform: transform,
    value_map: value_map,
  )

  @child_mappings = child_mappings
  @root_mappings = root_mappings
end

Instance Attribute Details

#child_mappingsObject (readonly)

Returns the value of attribute child_mappings.



6
7
8
# File 'lib/lutaml/model/mapping/key_value_mapping_rule.rb', line 6

def child_mappings
  @child_mappings
end

#root_mappingsObject (readonly)

Returns the value of attribute root_mappings.



6
7
8
# File 'lib/lutaml/model/mapping/key_value_mapping_rule.rb', line 6

def root_mappings
  @root_mappings
end

Instance Method Details

#deep_dupObject



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/lutaml/model/mapping/key_value_mapping_rule.rb', line 58

def deep_dup
  self.class.new(
    name.dup,
    to: to.dup,
    render_nil: render_nil.dup,
    render_empty: render_empty.dup,
    with: Utils.deep_dup(custom_methods),
    delegate: delegate,
    child_mappings: Utils.deep_dup(child_mappings),
    value_map: Utils.deep_dup(@value_map),
  )
end

#hash_mappingsObject



52
53
54
55
56
# File 'lib/lutaml/model/mapping/key_value_mapping_rule.rb', line 52

def hash_mappings
  return @root_mappings if @root_mappings

  @child_mappings
end

#root_mapping?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/lutaml/model/mapping/key_value_mapping_rule.rb', line 71

def root_mapping?
  name == "root_mapping"
end