Module: ActiveRecord::SnapshotView
- Defined in:
- lib/activerecord_snapshot_view/snapshot_view.rb
Defined Under Namespace
Modules: ClassMethods Classes: SaveWork
Class Method Summary collapse
- .class_from_symbol(sym) ⇒ Object
- .included(mod) ⇒ Object
-
.normalize(base_table) ⇒ Object
remove all SnapshotView related tables for a model, making it a normal model again does not require that the SnapshotView module is included on the model class.
-
.prepare_to_migrate(model_sym) ⇒ Object
prepare a SnapshotView model for migration...
Class Method Details
.class_from_symbol(sym) ⇒ Object
37 38 39 |
# File 'lib/activerecord_snapshot_view/snapshot_view.rb', line 37 def self.class_from_symbol(sym) eval(sym.to_s.camelize) end |
.included(mod) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/activerecord_snapshot_view/snapshot_view.rb', line 29 def self.included(mod) mod.instance_eval do class << self include ClassMethods end end end |
.normalize(base_table) ⇒ Object
remove all SnapshotView related tables for a model, making it a normal model again does not require that the SnapshotView module is included on the model class
59 60 61 62 63 64 65 66 67 |
# File 'lib/activerecord_snapshot_view/snapshot_view.rb', line 59 def self.normalize(base_table) view_tables = ActiveRecord::Base::connection.tables.select{|n| n=~ /^#{base_table}_([[:alpha:]]|switch)$/} $stderr << "#{base_table} matches no view_tables\n" if view_tables.empty? view_tables.each do |table| ActiveRecord::Base::connection.execute( "drop table #{table}" ) end end |
.prepare_to_migrate(model_sym) ⇒ Object
prepare a SnapshotView model for migration... move all data to the base table, make that current, and remove the other store tables. if the model no longer exists, or is no longer a SnapshotView, catch any errors
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/activerecord_snapshot_view/snapshot_view.rb', line 45 def self.prepare_to_migrate(model_sym) begin klass = class_from_symbol(model_sym) if klass.ancestors.include?(ActiveRecord::SnapshotView) klass.prepare_to_migrate end rescue Exception=>e $stderr << "model: #{model_sym} no longer exists?\nignored Exception:\n" $stderr << [e., *e.backtrace].join("\n") end end |