Module: Cardio::Seed

Defined in:
lib/cardio/seed.rb

Overview

methods in support of seeding

Constant Summary collapse

TABLES =
%w[cards card_actions card_acts card_changes card_references
schema_migrations transform_migrations].freeze

Class Method Summary collapse

Class Method Details

.cleanObject



40
41
42
43
44
# File 'lib/cardio/seed.rb', line 40

def clean
  Card::Act.update_all actor_id: author_id
  clean_history
  clean_time_and_user_stamps
end

.default_pathObject



8
9
10
# File 'lib/cardio/seed.rb', line 8

def default_path
  db_path Cardio.config.seed_type, 0
end

.dumpObject



29
30
31
32
33
34
35
36
37
38
# File 'lib/cardio/seed.rb', line 29

def dump
  dump_tables.each do |table|
    i = "000" # TODO: use card keys instead (this is just a label)
    write_seed_file table do
      yamlize_records table do |record, hash|
        hash["#{table}_#{i.succ!}"] = record
      end
    end
  end
end

.loadObject



20
21
22
23
24
25
26
27
# File 'lib/cardio/seed.rb', line 20

def load
  ActiveRecord::FixtureSet.create_fixtures path, load_tables

  return unless update_seed?

  Cardio::Migration::Schema.new.assume_current
  Cardio::Migration::Transform.new.assume_current
end

.pathObject



12
13
14
15
16
17
18
# File 'lib/cardio/seed.rb', line 12

def path
  if update_seed?
    db_path :real, (Rails.env.test? ? 0 : 1)
  else
    default_path
  end
end