Class: Dry::Initializer::Struct

Inherits:
Object
  • Object
show all
Extended by:
Dry::Initializer
Defined in:
lib/dry/initializer/struct.rb

Overview

The nested structure that takes nested hashes with indifferent access

Constant Summary

Constants included from Dry::Initializer

VERSION

Instance Attribute Summary

Attributes included from DSL

#null

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Dry::Initializer

dry_initializer, option, param

Methods included from DSL

#[], #define

Class Method Details

.new(options) ⇒ Object Also known as: call



10
11
12
# File 'lib/dry/initializer/struct.rb', line 10

def new(options)
  super(**Hash(options).each_with_object({}) { |(k, v), h| h[k.to_sym] = v })
end

Instance Method Details

#to_hHash<String, ...>

Represents event data as a nested hash with deeply stringified keys

Returns:

  • (Hash<String, ...>)


20
21
22
23
24
25
26
# File 'lib/dry/initializer/struct.rb', line 20

def to_h
  self
    .class
    .dry_initializer
    .attributes(self)
    .each_with_object({}) { |(k, v), h| h[k.to_s] = __hashify(v) }
end