class Dry::Initializer::Struct
Public Class Methods
new(options)
click to toggle source
Calls superclass method
# File lib/dry/initializer/struct.rb, line 13 def new(options) super(**Hash(options).each_with_object({}) { |(k, v), h| h[k.to_sym] = v }) end
Also aliased as: call
Public Instance Methods
to_h()
click to toggle source
Represents event data as a nested hash with deeply stringified keys @return [Hash<String, …>]
# File lib/dry/initializer/struct.rb, line 23 def to_h self .class .dry_initializer .attributes(self) .each_with_object({}) { |(k, v), h| h[k.to_s] = __hashify(v) } end
Private Instance Methods
__hashify(value)
click to toggle source
# File lib/dry/initializer/struct.rb, line 33 def __hashify(value) case value when Hash value.each_with_object({}) { |(k, v), obj| obj[k.to_s] = __hashify(v) } when Array then value.map { |v| __hashify(v) } when Dry::Initializer::Struct then value.to_h else value end end