Class: TableSync::Event
- Inherits:
-
Object
- Object
- TableSync::Event
- 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
-
#event ⇒ Object
readonly
Returns the value of attribute event.
Instance Method Summary collapse
- #destroy? ⇒ Boolean
-
#initialize(event) ⇒ Event
constructor
A new instance of Event.
- #metadata ⇒ Object
- #resolve ⇒ Object
- #upsert? ⇒ Boolean
- #validate! ⇒ Object
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
#event ⇒ Object (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
28 29 30 |
# File 'lib/table_sync/event.rb', line 28 def destroy? event == :destroy end |
#metadata ⇒ Object
24 25 26 |
# File 'lib/table_sync/event.rb', line 24 def { created: event == :create } end |
#resolve ⇒ Object
20 21 22 |
# File 'lib/table_sync/event.rb', line 20 def resolve destroy? ? :destroy : :update end |
#upsert? ⇒ 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 |