Module: Userstamp::MigrationHelper::InstanceMethods

Defined in:
lib/userstamp/migration_helper.rb

Instance Method Summary collapse

Instance Method Details

#stamps(options = {}) ⇒ Object


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/userstamp/migration_helper.rb', line 8

def stamps(options = {})
  groups = %i[time user lock]
  groups &= [options.delete(:only)].flatten if options[:only]
  groups -= [options.delete(:except)].flatten if options[:except]
  if groups.include?(:time)
    datetime(:created_at, null: false)
    datetime(:updated_at, null: false)
    index(:created_at)
    index(:updated_at)
  end
  if groups.include?(:user)
    references(:creator, index: true)
    references(:updater, index: true)
  end
  if groups.include?(:lock)
    integer(:lock_version, null: false, default: 0)
  end
end