Module: Bronze::Entities::Normalization

Extended by:
SleepingKingStudios::Tools::Toolbox::Mixin
Included in:
Bronze::Entity
Defined in:
lib/bronze/entities/normalization.rb

Overview

Module for transforming entities to and from a normal form.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#normalize(permit: []) ⇒ Hash

Returns a normalized representation of the entity. The normal representation of an entity is a hash with String keys. Each value must be nil, a literal value (true, false, a String, an Integer, a Float, etc), an Array of normal values, or a Hash with String keys and normal values.

Parameters:

  • permit (Array<Class>) (defaults to: [])

    An optional array of types to normalize as-is, rather than applying a transform. Only default transforms can be permitted, i.e. the built-in default transforms for BigDecimal, Date, DateTime, Symbol, and Time, or for an attribute with the :default_transform flag set to true.

Returns:

  • (Hash)

    The normal representation.



49
50
51
52
53
54
55
56
# File 'lib/bronze/entities/normalization.rb', line 49

def normalize(permit: [])
  self.class.each_attribute.with_object({}) do |(name, ), hsh|
    value = get_attribute(name)
    value = normalize_attribute(value, metadata: , permit: permit)

    hsh[name.to_s] = value
  end
end