Class: Cardio::Migration
- Inherits:
-
Object
show all
- Includes:
- Card::Model::SaveHelper
- Defined in:
- lib/cardio/migration.rb,
lib/cardio/migration/core.rb,
lib/cardio/migration/deck_structure.rb
Defined Under Namespace
Classes: Core, DeckStructure
Constant Summary
Card::Model::SaveHelper::SaveHelperHelper::CARDTYPE_METHOD_REGEXP
Class Method Summary
collapse
Instance Method Summary
collapse
#create_card, #create_card!, #delete_card, #delete_code_card, #update_card, #update_card!, #with_user
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Card::Model::SaveHelper::SaveHelperHelper
Class Method Details
.assume_current ⇒ Object
46
47
48
49
50
51
52
53
|
# File 'lib/cardio/migration.rb', line 46
def assume_current
migration_context do |mc|
versions = mc.migrations.map(&:version)
migrated = mc.get_all_versions
to_mark = versions - migrated
mark_as_migrated to_mark if to_mark.present?
end
end
|
.assume_migrated_upto_version ⇒ Object
.data_path(filename = nil) ⇒ Object
55
56
57
|
# File 'lib/cardio/migration.rb', line 55
def data_path filename=nil
File.join([migration_paths.first, "data", filename].compact)
end
|
.find_unused_name(base_name) ⇒ Object
20
21
22
23
24
25
26
27
28
|
# File 'lib/cardio/migration.rb', line 20
def find_unused_name base_name
test_name = base_name
add = 1
while Card.exists?(test_name)
test_name = "#{base_name}#{add}"
add += 1
end
test_name
end
|
.migration_paths(mig_type = type) ⇒ Object
30
31
32
|
# File 'lib/cardio/migration.rb', line 30
def migration_paths mig_type=type
Schema.migration_paths mig_type
end
|
.schema_mode(mig_type = type, &block) ⇒ Object
38
39
40
|
# File 'lib/cardio/migration.rb', line 38
def schema_mode mig_type=type, &block
Schema.mode mig_type, &block
end
|
.schema_suffix(mig_type = type) ⇒ Object
34
35
36
|
# File 'lib/cardio/migration.rb', line 34
def schema_suffix mig_type=type
Schema.suffix mig_type
end
|
.type ⇒ Object
Rake tasks use class methods, migrations use instance methods. To avoid repetition a lot of instance methods here just call class methods. The subclass Card::CoreMigration needs a different @type so we can’t use a class variable @@type. It has to be a class instance variable. Migrations are subclasses of Cardio::Migration or Card::CoreMigration but they don’t inherit the @type. The method below solves this problem.
16
17
18
|
# File 'lib/cardio/migration.rb', line 16
def type
@type || ancestors[1]&.type
end
|
Instance Method Details
#data_path(filename = nil) ⇒ Object
87
88
89
|
# File 'lib/cardio/migration.rb', line 87
def data_path filename=nil
self.class.data_path filename
end
|
#down ⇒ Object
108
109
110
|
# File 'lib/cardio/migration.rb', line 108
def down
raise ActiveRecord::IrreversibleMigration
end
|
#exec_migration(conn, direction) ⇒ Object
Execute this migration in the named direction copied from ActiveRecord to wrap ‘up’ in ‘contentedly’
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/cardio/migration.rb', line 93
def exec_migration conn, direction
@connection = conn
if respond_to?(:change)
if direction == :down
revert { change }
else
change
end
else
contentedly { send(direction) }
end
ensure
@connection = nil
end
|