Module: TableSync::Receiving::DSL

Included in:
Handler
Defined in:
lib/table_sync/receiving/dsl.rb

Instance Method Summary collapse

Instance Method Details

#configsObject



10
11
12
# File 'lib/table_sync/receiving/dsl.rb', line 10

def configs
  @configs ||= Hash.new { |hash, key| hash[key] = [] }
end

#inherited(klass) ⇒ Object



5
6
7
8
# File 'lib/table_sync/receiving/dsl.rb', line 5

def inherited(klass)
  klass.instance_variable_set(:@configs, configs.deep_dup)
  super
end

#receive(source, to_table: nil, to_model: nil, events: [:update, :destroy], &block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/table_sync/receiving/dsl.rb', line 14

def receive(source, to_table: nil, to_model: nil, events: [:update, :destroy], &block)
  model = to_table ? TableSync.receiving_model.new(to_table) : to_model

  TableSync::Utils::InterfaceChecker.new(model).implements(:receiving_model)

  config = ::TableSync::Receiving::Config.new(model: model, events: events)

  config.instance_exec(&block) if block

  configs[source.to_s] << config

  self
end