Class: MaglevRecord::ClassChange
- Defined in:
- lib/maglev_record/snapshot/class_change.rb
Overview
Change of a class between two class snapshots
Instance Method Summary collapse
- #changed_class ⇒ Object
- #class_name ⇒ Object
-
#initialize(old, new) ⇒ ClassChange
constructor
A new instance of ClassChange.
- #migration_string_list ⇒ Object
- #new_attributes ⇒ Object
- #new_class_methods ⇒ Object
- #new_instance_methods ⇒ Object
- #removed_attributes ⇒ Object
- #removed_class_methods ⇒ Object
- #removed_instance_methods ⇒ Object
Constructor Details
#initialize(old, new) ⇒ ClassChange
Returns a new instance of ClassChange.
7 8 9 10 |
# File 'lib/maglev_record/snapshot/class_change.rb', line 7 def initialize(old, new) @old = old @new = new end |
Instance Method Details
#changed_class ⇒ Object
24 25 26 |
# File 'lib/maglev_record/snapshot/class_change.rb', line 24 def changed_class @old.snapshot_class end |
#class_name ⇒ Object
20 21 22 |
# File 'lib/maglev_record/snapshot/class_change.rb', line 20 def class_name @old.class_name end |
#migration_string_list ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/maglev_record/snapshot/class_change.rb', line 28 def migration_string_list if removed_attributes.size == 1 and new_attributes.size == 1 from_attr = removed_attributes.first to_attr = new_attributes.first ["#{class_name}.rename_attribute(:#{from_attr}, :#{to_attr})"] else removed_attributes.map{ |attr| "#{class_name}.delete_attribute(:#{attr})" } + new_attributes.map{ |attr| "#new accessor :#{attr} of #{class_name}" } end + new_class_methods.map{ |cm| "#new class method: #{class_name}.#{cm.to_s}" } + new_instance_methods.map{ |im| "#new instance method: #{class_name}.new.#{im.to_s}" } + removed_class_methods.map{ |cm| "#{class_name}.remove_class_method :#{cm}" } + removed_instance_methods.map{ |im| "#{class_name}.remove_instance_method :#{im}" } end |
#new_attributes ⇒ Object
12 13 14 |
# File 'lib/maglev_record/snapshot/class_change.rb', line 12 def new_attributes (@new.attributes - @old.attributes).sort end |
#new_class_methods ⇒ Object
58 59 60 |
# File 'lib/maglev_record/snapshot/class_change.rb', line 58 def new_class_methods (@new.class_methods - @old.class_methods).sort end |
#new_instance_methods ⇒ Object
50 51 52 |
# File 'lib/maglev_record/snapshot/class_change.rb', line 50 def new_instance_methods (@new.instance_methods - @old.instance_methods).sort end |
#removed_attributes ⇒ Object
16 17 18 |
# File 'lib/maglev_record/snapshot/class_change.rb', line 16 def removed_attributes (@old.attributes - @new.attributes).sort end |
#removed_class_methods ⇒ Object
62 63 64 |
# File 'lib/maglev_record/snapshot/class_change.rb', line 62 def removed_class_methods (@old.class_methods - @new.class_methods).sort end |
#removed_instance_methods ⇒ Object
54 55 56 |
# File 'lib/maglev_record/snapshot/class_change.rb', line 54 def removed_instance_methods (@old.instance_methods - @new.instance_methods).sort end |