Sha256: 395ad1c4e67a61dab0927a62a07f098c837bd01c4b23f9eb6c4a4e32005ff9a3

Contents?: true

Size: 1.11 KB

Versions: 3

Compression:

Stored size: 1.11 KB

Contents

require_relative "mapping_rule"

module Lutaml
  module Model
    class KeyValueMappingRule < MappingRule
      attr_reader :child_mappings,
                  :root_mappings

      def initialize(
        name,
        to:,
        render_nil: false,
        render_default: false,
        with: {},
        delegate: nil,
        child_mappings: nil,
        root_mappings: nil
      )
        super(
          name,
          to: to,
          render_nil: render_nil,
          render_default: render_default,
          with: with,
          delegate: delegate
        )

        @child_mappings = child_mappings
        @root_mappings = root_mappings
      end

      def hash_mappings
        return @root_mappings if @root_mappings

        @child_mappings
      end

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

      def root_mapping?
        name == "root_mapping"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
lutaml-model-0.5.3 lib/lutaml/model/key_value_mapping_rule.rb
lutaml-model-0.5.2 lib/lutaml/model/key_value_mapping_rule.rb
lutaml-model-0.5.1 lib/lutaml/model/key_value_mapping_rule.rb