Module: EntityProjection

Included in:
Controls::Projection::Anomaly::NoApply::Example, Controls::Projection::ApplyMethod::EventData::Example, Controls::Projection::ApplyMethod::Message::Example, Controls::Projection::BlockAndApplyMethod::Example, Controls::Projection::Example, Controls::Projection::RegisterMessageClass::Example
Defined in:
lib/entity_projection/log.rb,
lib/entity_projection/controls/entity.rb,
lib/entity_projection/controls/message.rb,
lib/entity_projection/entity_projection.rb,
lib/entity_projection/controls/event_data.rb,
lib/entity_projection/controls/projection.rb

Defined Under Namespace

Modules: ApplyMacro, Build, Call, Controls, EntityNameMacro, EventRegistry, Info, Register Classes: Log

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(cls) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/entity_projection/entity_projection.rb', line 2

def self.included(cls)
  cls.class_exec do
    include Initializer
    include Virtual
    include Log::Dependency

    extend Build
    extend Call
    extend Info
    extend ApplyMacro
    extend EventRegistry
    extend Register
    extend EntityNameMacro

    virtual :configure

    initializer :entity
  end
end

Instance Method Details

#apply_event(event) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/entity_projection/entity_projection.rb', line 134

def apply_event(event)
  logger.trace(tag: :apply) { "Applying event (Event class: #{event.class.name})" }
  logger.trace(tags: [:data, :message]) { event.pretty_inspect }

  handler = self.class.handler(event)

  unless handler.nil?
    public_send(handler, event)
  else
    if respond_to?(:apply)
      apply(event)
    end
  end

  logger.info(tag: :apply) { "Applied event (Event class: #{event.class.name})" }
  logger.trace(tags: [:data, :message]) { event.pretty_inspect }

  event
end

#apply_event_data(event_data) ⇒ Object



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/entity_projection/entity_projection.rb', line 154

def apply_event_data(event_data)
  logger.trace(tag: :apply) { "Applying event data (Type: #{event_data.type})" }
  logger.trace(tags: [:data, :message_data]) { event_data.pretty_inspect }

  res = nil

  handler = self.class.handler(event_data)

  unless handler.nil?
    event_name = Messaging::Message::Info.canonize_name(event_data.type)
    event_class = self.class.event_registry.get(event_name)
    res = Messaging::Message::Import.(event_data, event_class)
    public_send(handler, res)
  else
    if respond_to?(:apply)
      res = apply(event_data)
    end
  end

  logger.info(tag: :apply) { "Applied event data (Type: #{event_data.type})" }
  logger.info(tags: [:data, :message_data]) { event_data.pretty_inspect }

  res
end

#call(event_or_event_data) ⇒ Object



126
127
128
129
130
131
132
# File 'lib/entity_projection/entity_projection.rb', line 126

def call(event_or_event_data)
  if event_or_event_data.is_a?(Messaging::Message)
    apply_event(event_or_event_data)
  else
    apply_event_data(event_or_event_data)
  end
end