Module: Sequent::Core::Helpers::AutosetAttributes::ClassMethods

Defined in:
lib/sequent/core/helpers/autoset_attributes.rb

Constant Summary collapse

@@autoset_ignore_attributes =
%w[aggregate_id sequence_number created_at]

Instance Method Summary collapse

Instance Method Details

#autoset_attributes_for_events(*args) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/sequent/core/helpers/autoset_attributes.rb', line 39

def autoset_attributes_for_events(*args)
  args.each do |arg|
    on arg do |event|
      self.class.event_attribute_keys(event.class).each do |attribute_name|
        instance_variable_set(:"@#{attribute_name}", event.public_send(attribute_name.to_sym))
      end
    end
  end
end

#event_attribute_keys(event_class) ⇒ Object



35
36
37
# File 'lib/sequent/core/helpers/autoset_attributes.rb', line 35

def event_attribute_keys(event_class)
  event_class.types.keys.reject { |k| @@autoset_ignore_attributes.include?(k.to_s) }
end

#set_autoset_ignore_attributes(attribute_names) ⇒ Object



31
32
33
# File 'lib/sequent/core/helpers/autoset_attributes.rb', line 31

def set_autoset_ignore_attributes(attribute_names)
  @@autoset_ignore_attributes = attribute_names
end