Class: TableSync::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/table_sync/event.rb

Constant Summary collapse

UPSERT_EVENTS =
%i[create update].freeze
VALID_RESOLVED_EVENTS =
%i[update destroy].freeze
VALID_RAW_EVENTS =
%i[create update destroy].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event) ⇒ Event

Returns a new instance of Event.



10
11
12
13
14
# File 'lib/table_sync/event.rb', line 10

def initialize(event)
  @event = event

  validate!
end

Instance Attribute Details

#eventObject (readonly)

Returns the value of attribute event.



4
5
6
# File 'lib/table_sync/event.rb', line 4

def event
  @event
end

Instance Method Details

#destroy?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/table_sync/event.rb', line 28

def destroy?
  event == :destroy
end

#metadataObject



24
25
26
# File 'lib/table_sync/event.rb', line 24

def 
  { created: event == :create }
end

#resolveObject



20
21
22
# File 'lib/table_sync/event.rb', line 20

def resolve
  destroy? ? :destroy : :update
end

#upsert?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/table_sync/event.rb', line 32

def upsert?
  event.in?(UPSERT_EVENTS)
end

#validate!Object



16
17
18
# File 'lib/table_sync/event.rb', line 16

def validate!
  raise TableSync::EventError.new(event) unless event.in?(VALID_RAW_EVENTS)
end