Class: CDP::Builders::AfterCreated

Inherits:
Object
  • Object
show all
Defined in:
lib/cdp/builders/after_created.rb

Instance Method Summary collapse

Constructor Details

#initialize(builder, source) ⇒ AfterCreated

Returns a new instance of AfterCreated.

Raises:

  • (ArgumentError)


4
5
6
7
8
9
# File 'lib/cdp/builders/after_created.rb', line 4

def initialize(builder, source)
  raise ArgumentError, 'Unsupported multiple commands' if source.commands.size > 1
  raise ArgumentError, 'Only supported on upsert' if source.commands.first&.upsert_entity.blank?
  @builder = builder
  @source = source
end

Instance Method Details

#create_event(target) ⇒ Object

Raises:

  • (ArgumentError)


19
20
21
22
23
24
25
# File 'lib/cdp/builders/after_created.rb', line 19

def create_event(target)
  raise ArgumentError, 'Unsupported multiple commands' if target.commands.size > 1
  raise ArgumentError, 'Supported only create event' unless target.commands.first&.create_event.present?

  @source.commands.first.upsert_entity.if_created_create_event << target.commands.first
  @source
end

#relate_to(target) ⇒ Object

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
# File 'lib/cdp/builders/after_created.rb', line 11

def relate_to(target)
  raise ArgumentError, 'Unsupported multiple commands' if target.commands.size > 1
  raise ArgumentError, 'Supported only create entity' unless target.commands.first&.create_entity.present?

  @source.commands.first.upsert_entity.if_created_relate_with << target.commands.first
  @source
end