Module: Replication::Process

Defined in:
lib/replication/process.rb

Defined Under Namespace

Modules: Model

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(model_class) ⇒ Object



4
5
6
7
8
# File 'lib/replication/process.rb', line 4

def self.extended(model_class)
  model_class.class_eval do
    include Model
  end
end

.included(model_class) ⇒ Object

Include or extend it. We work with both.



11
12
13
# File 'lib/replication/process.rb', line 11

def self.included(model_class)
  model_class.extend self
end

Instance Method Details

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



15
16
17
18
19
20
21
22
23
24
# File 'lib/replication/process.rb', line 15

def can_replicate(pairs_method = :attributes, **options)
  @@replication_config = Class.new(Config).new(self)
  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
end

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



26
27
28
29
30
31
32
33
34
# File 'lib/replication/process.rb', line 26

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



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

def replication_config
  @@replication_config
end