Module: Cardio::Schema
- Defined in:
- lib/cardio/schema.rb
Class Method Summary collapse
- .assume_migrated_upto_version(type, version = nil) ⇒ Object
- .migrate(type, version = nil, verbose = true) ⇒ Object
- .migration_context(type) ⇒ Object
- .migration_paths(type) ⇒ Object
- .mode(type) ⇒ Object
- .stamp_path(type) ⇒ Object
- .suffix(type) ⇒ Object
- .version(type = nil) ⇒ Object
Class Method Details
.assume_migrated_upto_version(type, version = nil) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/cardio/schema.rb', line 4 def assume_migrated_upto_version type, version=nil mode type do |_paths| version ||= version type ActiveRecord::Schema.assume_migrated_upto_version version end end |
.migrate(type, version = nil, verbose = true) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/cardio/schema.rb', line 11 def migrate type, version=nil, verbose=true migration_context type do |mc| ActiveRecord::Migration.verbose = verbose mc.migrate version end end |
.migration_context(type) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/cardio/schema.rb', line 58 def migration_context type with_suffix type do yield ActiveRecord::MigrationContext.new(migration_paths(type), ActiveRecord::SchemaMigration) end end |
.migration_paths(type) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/cardio/schema.rb', line 45 def migration_paths type list = Cardio.paths["db/migrate#{suffix type}"].to_a case type when :core_cards list += mod_migration_paths "migrate_core_cards" when :deck_cards list += mod_migration_paths "migrate_cards" when :deck list += mod_migration_paths "migrate" end list.flatten end |
.mode(type) ⇒ Object
27 28 29 30 31 |
# File 'lib/cardio/schema.rb', line 27 def mode type with_suffix type do yield migration_paths(type) end end |
.stamp_path(type) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/cardio/schema.rb', line 38 def stamp_path type root_dir = deck_migration?(type) ? Cardio.root : Cardio.gem_root stamp_dir = ENV["SCHEMA_STAMP_PATH"] || File.join(root_dir, "db") File.join stamp_dir, "version#{suffix type}.txt" end |
.suffix(type) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/cardio/schema.rb', line 18 def suffix type case type when :core_cards then "_core_cards" when :deck_cards then "_deck_cards" when :deck then "_deck" else "" end end |
.version(type = nil) ⇒ Object
33 34 35 36 |
# File 'lib/cardio/schema.rb', line 33 def version type=nil path = stamp_path type File.exist?(path) ? File.read(path).strip : nil end |