Module: Replication::Process

Defined in:
lib/replication/process.rb

Instance Method Summary collapse

Instance Method Details

#can_replicate(pairs_method = :attributes, **options) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/replication/process.rb', line 4

def can_replicate(pairs_method = :attributes, **options)
  reset_config if self.respond_to?(:unwound)

  puts replication_config.inspect

  default_options = Replication.defaults
  modules = [:semi_conservative] # required module
  modules.concat([].push(options.delete(:with)).flatten).compact!

  replication_config.pairs_method = pairs_method
  replication_config.set default_options.merge(options)
  replication_config.with modules

  include Model
end

#new_from_strand(id = nil, **options) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/replication/process.rb', line 20

def new_from_strand(id=nil, **options)
  if id
    strand = replication_config.strand_class.to_adapter.get!(id)
  else
    strand = replication_config.strand_class.to_adapter.find_first(options)
  end

  new(strand.pairs) if strand
end

#replication_configObject



34
35
36
37
38
# File 'lib/replication/process.rb', line 34

def replication_config
  @replication_config ||= base_class.replication_config.dup.tap do |config|
    config.model_class = self
  end
end

#reset_configObject



30
31
32
# File 'lib/replication/process.rb', line 30

def reset_config
  @replication_config = nil
end