Module: Cardio::Schema
- Defined in:
- lib/cardio/schema.rb
Class Method Summary collapse
- .assume_migrated_upto_version(type) ⇒ Object
- .migrate(type, version = nil, verbose = true) ⇒ 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) ⇒ Object
4 5 6 7 8 |
# File 'lib/cardio/schema.rb', line 4 def assume_migrated_upto_version type mode type do |paths| ActiveRecord::Schema.assume_migrated_upto_version version(type), paths end end |
.migrate(type, version = nil, verbose = true) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/cardio/schema.rb', line 10 def migrate type, version=nil, verbose=true migration_context type do |mc| ActiveRecord::Migration.verbose = verbose mc.migrate version end end |
.migration_paths(type) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/cardio/schema.rb', line 43 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
26 27 28 29 30 |
# File 'lib/cardio/schema.rb', line 26 def mode type with_suffix type do yield migration_paths(type) end end |
.stamp_path(type) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/cardio/schema.rb', line 36 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
17 18 19 20 21 22 23 24 |
# File 'lib/cardio/schema.rb', line 17 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
32 33 34 |
# File 'lib/cardio/schema.rb', line 32 def version type=nil File.read(stamp_path(type)).strip end |