Class: Dionysus::Consumer::DionysusEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/dionysus/consumer/dionysus_event.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event_name, model_name, transformed_data, aggregate_root: true) ⇒ DionysusEvent

Returns a new instance of DionysusEvent.



6
7
8
9
10
11
12
# File 'lib/dionysus/consumer/dionysus_event.rb', line 6

def initialize(event_name, model_name, transformed_data, aggregate_root: true)
  @event_name = event_name.to_s
  @model_name = model_name.to_s
  @transformed_data = transformed_data
  @local_changes = {}
  @aggregate_root = aggregate_root
end

Instance Attribute Details

#event_nameObject (readonly)

Returns the value of attribute event_name.



4
5
6
# File 'lib/dionysus/consumer/dionysus_event.rb', line 4

def event_name
  @event_name
end

#local_changesObject (readonly)

Returns the value of attribute local_changes.



4
5
6
# File 'lib/dionysus/consumer/dionysus_event.rb', line 4

def local_changes
  @local_changes
end

#model_nameObject (readonly)

Returns the value of attribute model_name.



4
5
6
# File 'lib/dionysus/consumer/dionysus_event.rb', line 4

def model_name
  @model_name
end

#transformed_dataObject (readonly)

Returns the value of attribute transformed_data.



4
5
6
# File 'lib/dionysus/consumer/dionysus_event.rb', line 4

def transformed_data
  @transformed_data
end

Instance Method Details

#aggregate_root?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/dionysus/consumer/dionysus_event.rb', line 30

def aggregate_root?
  @aggregate_root == true
end

#created?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/dionysus/consumer/dionysus_event.rb', line 14

def created?
  event_name.end_with?("created")
end

#destroyed?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/dionysus/consumer/dionysus_event.rb', line 22

def destroyed?
  event_name.end_with?("destroyed")
end

#generic_event?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/dionysus/consumer/dionysus_event.rb', line 26

def generic_event?
  created? || updated? || destroyed?
end

#to_hObject



34
35
36
37
38
39
40
41
# File 'lib/dionysus/consumer/dionysus_event.rb', line 34

def to_h
  {
    event_name: event_name,
    model_name: model_name,
    transformed_data: transformed_data,
    local_changes: local_changes
  }
end

#updated?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/dionysus/consumer/dionysus_event.rb', line 18

def updated?
  event_name.end_with?("updated")
end