Module: SafeMigrations::MigrationExt::ClassMethods
- Defined in:
- lib/safe_migrations/migration_ext.rb
Constant Summary collapse
- UNSAFE_METHODS =
[:drop_table, :remove_column]
Class Method Summary collapse
Instance Method Summary collapse
- #method_missing_with_safety(method, *args, &block) ⇒ Object
- #safe? ⇒ Boolean
- #safety_assured(&block) ⇒ Object
Class Method Details
.extended(base) ⇒ Object
6 7 8 9 10 |
# File 'lib/safe_migrations/migration_ext.rb', line 6 def self.extended(base) class << base alias_method_chain :method_missing, :safety end end |
Instance Method Details
#method_missing_with_safety(method, *args, &block) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/safe_migrations/migration_ext.rb', line 23 def method_missing_with_safety(method, *args, &block) if safe? || !UNSAFE_METHODS.include?(method) return method_missing_without_safety(method, *args, &block) end case method when :remove_column raise UnsafeRemoveColumn when :drop_table raise UnsafeDropTable end end |
#safe? ⇒ Boolean
19 20 21 |
# File 'lib/safe_migrations/migration_ext.rb', line 19 def safe? !!@safety end |
#safety_assured(&block) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/safe_migrations/migration_ext.rb', line 12 def safety_assured(&block) @safety = true yield ensure @safety = false end |