Class: Shale::Mapping::DictBase Private

Inherits:
Object
  • Object
show all
Defined in:
lib/shale/mapping/dict_base.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Base class for Mapping dictionary serialization formats (Hash/JSON/YAML/TOML/CSV)

Direct Known Subclasses

Dict, DictGroup

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(render_nil_default: false) ⇒ DictBase

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize instance

Parameters:

  • render_nil_default (true, false) (defaults to: false)


31
32
33
34
35
36
# File 'lib/shale/mapping/dict_base.rb', line 31

def initialize(render_nil_default: false)
  @keys = {}
  @root = {}
  @finalized = false
  @render_nil_default = render_nil_default
end

Instance Attribute Details

#keysHash (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return keys mapping hash

Returns:

  • (Hash)


17
18
19
# File 'lib/shale/mapping/dict_base.rb', line 17

def keys
  @keys
end

#rootHash (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return hash for hash with properties for root Object

Returns:

  • (Hash)


24
25
26
# File 'lib/shale/mapping/dict_base.rb', line 24

def root
  @root
end

Instance Method Details

#finalize!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Set the “finalized” instance variable to true



85
86
87
# File 'lib/shale/mapping/dict_base.rb', line 85

def finalize!
  @finalized = true
end

#finalized?truem false

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Query the “finalized” instance variable

Returns:

  • (truem false)


94
95
96
# File 'lib/shale/mapping/dict_base.rb', line 94

def finalized?
  @finalized
end

#initialize_dup(other) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



99
100
101
102
103
# File 'lib/shale/mapping/dict_base.rb', line 99

def initialize_dup(other)
  @keys = other.instance_variable_get('@keys').dup
  @finalized = false
  super
end

#map(key, to: nil, receiver: nil, using: nil, group: nil, render_nil: nil, schema: nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Map key to attribute

Parameters:

  • key (String)
  • to (Symbol, nil) (defaults to: nil)
  • receiver (Symbol, nil) (defaults to: nil)
  • using (Hash, nil) (defaults to: nil)
  • group (String, nil) (defaults to: nil)
  • render_nil (true, false, nil) (defaults to: nil)
  • schema (Hash, nil) (defaults to: nil)

Raises:



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/shale/mapping/dict_base.rb', line 51

def map(key, to: nil, receiver: nil, using: nil, group: nil, render_nil: nil, schema: nil)
  Validator.validate_arguments(key, to, receiver, using)

  @keys[key] = Descriptor::Dict.new(
    name: key,
    attribute: to,
    receiver: receiver,
    methods: using,
    group: group,
    render_nil: render_nil.nil? ? @render_nil_default : render_nil,
    schema: schema
  )
end

#properties(min_properties: nil, max_properties: nil, dependent_required: nil, additional_properties: nil) ⇒ Object

Allow schema properties to be set on the object

Parameters:

  • min_properties (Integer) (defaults to: nil)
  • max_properties (Integer) (defaults to: nil)
  • dependent_required (Hash) (defaults to: nil)
  • additional_properties (Boolean) (defaults to: nil)


73
74
75
76
77
78
79
80
# File 'lib/shale/mapping/dict_base.rb', line 73

def properties(min_properties: nil, max_properties: nil, dependent_required: nil, additional_properties: nil)
  @root = {
    min_properties: min_properties,
    max_properties: max_properties,
    dependent_required: dependent_required,
    additional_properties: additional_properties,
  }
end