Class: CloneKit::Operation

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/clone_kit/operation.rb

Defined Under Namespace

Classes: BatchCompleteHandler

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arguments: {}, id: SecureRandom.uuid, already_cloned: [], strategy: Strategies::Synchronous, event_outlet: CloneKit::EventOutlet.new) ⇒ Operation

Returns a new instance of Operation.



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/clone_kit/operation.rb', line 16

def initialize(arguments: {},
               id: SecureRandom.uuid,
               already_cloned: [],
               strategy: Strategies::Synchronous,
               event_outlet: CloneKit::EventOutlet.new)
  self.id = id
  self.arguments = arguments
  self.already_cloned = already_cloned
  self.event_outlet = event_outlet
  self.strategy = strategy.new(self)
end

Instance Attribute Details

#already_clonedObject

Returns the value of attribute already_cloned.



12
13
14
# File 'lib/clone_kit/operation.rb', line 12

def already_cloned
  @already_cloned
end

#argumentsObject

Returns the value of attribute arguments.



12
13
14
# File 'lib/clone_kit/operation.rb', line 12

def arguments
  @arguments
end

#idObject

Returns the value of attribute id.



12
13
14
# File 'lib/clone_kit/operation.rb', line 12

def id
  @id
end

Instance Method Details

#processObject



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/clone_kit/operation.rb', line 28

def process
  if next_batch.empty?
    # Done!
    after_process
  elsif first_unspecified_model_dependency.present?
    fail "A clone dependency was added for #{first_unspecified_model_dependency}, but it has no clone specification"
  else
    specs = next_batch.map { |model| CloneKit.spec[model] }
    strategy.clone_next_batch(specs, BatchCompleteHandler)
  end
end