Module: Aggro::AttributeDSL

Extended by:
ActiveSupport::Concern
Includes:
ActiveModel::Model, ActiveModel::Validations::Callbacks
Included in:
Command, Query, Saga
Defined in:
lib/aggro/attribute_dsl.rb

Overview

Public: Adds a DSL defining attributes and validations.

Instance Method Summary collapse

Instance Method Details

#attributesObject



21
22
23
24
25
# File 'lib/aggro/attribute_dsl.rb', line 21

def attributes
  self.class.attributes.keys.reduce({}) do |hash, name|
    hash.merge name => send(name)
  end
end

#initialize(attrs = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/aggro/attribute_dsl.rb', line 9

def initialize(attrs = {})
  if Thread.current[:causation_id] && respond_to?(:causation_id=)
    attrs.merge! causation_id: Thread.current[:causation_id]
  end

  if Thread.current[:correlation_id] && respond_to?(:correlation_id=)
    attrs.merge! correlation_id: Thread.current[:correlation_id]
  end

  super
end

#serialized_attributesObject



27
28
29
30
31
# File 'lib/aggro/attribute_dsl.rb', line 27

def serialized_attributes
  self.class.attributes.reduce({}) do |hash, (name, transform)|
    hash.merge name => transform.serialize(send(name))
  end
end