Class: Hexx::Entities::Part

Inherits:
Object
  • Object
show all
Includes:
Attestor::Validations, Comparable, Eigindir
Defined in:
lib/hexx-entities/part.rb

Overview

Class Part provides a common interface for parts of aggregate entities

Examples:

require "hexx-entities"

class Item < Hexx::Entities::Part

  # Defines attributes with their coercers
  attribute :foo, coerce: ->(value) { value.to_s }

  # Defines validation for the entity
  validate { invalid :blank_foo unless foo }

end # class Item

Direct Known Subclasses

Base

Class Method Summary collapse

Class Method Details

.initialize(**attributes) ⇒ Object



37
38
39
40
# File 'lib/hexx-entities/part.rb', line 37

def initialize(**attributes)
  self.attributes = attributes
  freeze
end

.new(attributes) ⇒ Hexx::Entities::Part

Creates the immutable object

Parameters:

  • attributes (Hash)

Returns:



# File 'lib/hexx-entities/part.rb', line 28


.serializeHash

Recursively serializes the part to the hash

Returns the hash of attributes, where every attribute that responds to ‘serialize` is serialized in its turn.

Returns:

  • (Hash)


48
49
50
# File 'lib/hexx-entities/part.rb', line 48

def serialize
  attributes.map { |key, value| [key, serialize__(value)] }.to_h
end