Module: Mongoid::LazyMigration::Document

Defined in:
lib/mongoid/lazy_migration/document.rb

Instance Method Summary collapse

Instance Method Details

#atomic_selectorObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/mongoid/lazy_migration/document.rb', line 11

def atomic_selector
  return super unless @migrating

  if @running_migrate_block && !self.class.lock_migration
      raise ["You cannot save during an atomic migration,",
             "You are only allowed to set the document fields",
             "The document will be commited once the migration is complete.",
             "If you need to get fancy, like creating associations, use :lock => true"
      ].join("\n")
  end

  # see perform migration
  super.merge(:migration_state => { "$ne" => :done })
end

#ensure_migrationObject



2
3
4
5
6
7
8
9
# File 'lib/mongoid/lazy_migration/document.rb', line 2

def ensure_migration
  self.migration_state = :done if new_record?

  @migrating = true
  perform_migration if migration_state == :pending
  wait_for_completion if migration_state == :processing
  @migrating = false
end

#run_callbacks(*args, &block) ⇒ Object



26
27
28
29
30
# File 'lib/mongoid/lazy_migration/document.rb', line 26

def run_callbacks(*args, &block)
  return super(*args, &block) unless @migrating

  block.call if block
end