class Bronze::Transforms::Entities::NormalizeTransform
Transform
class that maps an entity to a normal representation.
Attributes
entity_class[R]
@return [Class] the entity class to normalize.
permitted_types[R]
@return [Array<Class>] array of types to normalize as-is.
Public Class Methods
new(entity_class, permit: [])
click to toggle source
@param [Class] entity_class
The entity class to normalize. @param [Array<Class>] permit 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.
# File lib/bronze/transforms/entities/normalize_transform.rb, line 15 def initialize(entity_class, permit: []) @entity_class = entity_class @permitted_types = permit end
Public Instance Methods
denormalize(attributes)
click to toggle source
Returns an entity instance.
@param attributes [Hash] The normal representation of an entity.
@return [Bronze::Entity] the entity instance.
@see [Bronze::Entities::Normalization::denormalize]
# File lib/bronze/transforms/entities/normalize_transform.rb, line 33 def denormalize(attributes) return nil if attributes.nil? entity_class.denormalize(attributes) end
normalize(entity)
click to toggle source
Returns a normalized representation of the entity.
@param entity [Bronze::Entity] The entity to normalize.
@return [Hash] the normal representation.
@see [Bronze::Entities::Normalization#normalize]
# File lib/bronze/transforms/entities/normalize_transform.rb, line 46 def normalize(entity) return nil if entity.nil? entity.normalize(permit: permitted_types) end