Sha256: 0bbf28cf86a655ef64f3566b314c0498a2c78fb4a4f16f12c32a2904b7151877

Contents?: true

Size: 616 Bytes

Versions: 11

Compression:

Stored size: 616 Bytes

Contents

# frozen_string_literal: true

class TableSync::Event
  attr_reader :event

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

  def initialize(event)
    @event = event

    validate!
  end

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

  def resolve
    destroy? ? :destroy : :update
  end

  def metadata
    { created: event == :create }
  end

  def destroy?
    event == :destroy
  end

  def upsert?
    event.in?(UPSERT_EVENTS)
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
table_sync-6.5.1 lib/table_sync/event.rb
table_sync-6.5.0 lib/table_sync/event.rb
table_sync-6.4.2 lib/table_sync/event.rb
table_sync-6.4.1 lib/table_sync/event.rb
table_sync-6.4.0 lib/table_sync/event.rb
table_sync-6.3.0 lib/table_sync/event.rb
table_sync-6.1.0 lib/table_sync/event.rb
table_sync-6.0.4 lib/table_sync/event.rb
table_sync-6.0.3 lib/table_sync/event.rb
table_sync-6.0.2 lib/table_sync/event.rb
table_sync-6.0 lib/table_sync/event.rb