Class: MaglevRecord::Change

Inherits:
Object show all
Defined in:
lib/maglev_record/snapshot/change.rb

Overview

The Change between two snapshots of the image

Instance Method Summary collapse

Constructor Details

#initialize(old, new) ⇒ Change

Returns a new instance of Change.



9
10
11
12
# File 'lib/maglev_record/snapshot/change.rb', line 9

def initialize(old, new)
  @old = old
  @new = new
end

Instance Method Details

#[](class_or_class_name) ⇒ Object



76
77
78
79
80
81
# File 'lib/maglev_record/snapshot/change.rb', line 76

def [](class_or_class_name)
  changed_classes.each{ |change|
    return change if change.changed_class == class_or_class_name or
                     change.class_name == class_or_class_name
  }
end

#changed_class_namesObject



27
28
29
# File 'lib/maglev_record/snapshot/change.rb', line 27

def changed_class_names
  changed_classes.map(&:class_name).sort
end

#changed_classesObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/maglev_record/snapshot/change.rb', line 14

def changed_classes
  changes = []
  @new.class_snapshots.each{ |new|
    @old.class_snapshots.each { |old|
      if  old == new and
          new.changed_since? old
        changes << new.changes_since(old)
      end
    }
  }
  changes
end

#migration_string(identation = 0) ⇒ Object



68
69
70
# File 'lib/maglev_record/snapshot/change.rb', line 68

def migration_string(identation = 0)
  " " * identation + migration_string_list.select{ |s| s.strip != ""}.join("\n" + " " * identation)
end

#migration_string_listObject



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/maglev_record/snapshot/change.rb', line 55

def migration_string_list
  if removed_classes.size == 1 and new_classes.size == 1
    ["rename_class #{removed_class_names.first
              }, :#{new_class_names.first}"]
  else
    removed_class_names.map{ |class_name|
      "delete_class #{class_name}"
    } + new_class_names.map{ |class_name|
      "#new class: #{class_name}"
    }
  end + changed_classes.map(&:migration_string_list).flatten
end

#new_class_namesObject



51
52
53
# File 'lib/maglev_record/snapshot/change.rb', line 51

def new_class_names
  new_classes.map(&:class_name).sort
end

#new_classesObject



43
44
45
46
47
48
49
# File 'lib/maglev_record/snapshot/change.rb', line 43

def new_classes
  @new.class_snapshots.select{ |new|
    new.exists? and @old.class_snapshots.all?{ |old|
      old != new
    }
  }
end

#nothing_changed?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/maglev_record/snapshot/change.rb', line 72

def nothing_changed?
  removed_classes == [] and changed_classes == [] and new_classes == []
end

#removed_class_namesObject



39
40
41
# File 'lib/maglev_record/snapshot/change.rb', line 39

def removed_class_names
  removed_classes.map(&:class_name).sort
end

#removed_classesObject



31
32
33
34
35
36
37
# File 'lib/maglev_record/snapshot/change.rb', line 31

def removed_classes
  @old.class_snapshots.select{ |old|
    old.exists? and @new.class_snapshots.all?{ |new|
      old != new
    }
  }
end

#reversedObject



87
88
89
# File 'lib/maglev_record/snapshot/change.rb', line 87

def reversed
  self.class.new(@new, @old)
end

#superclass_mismatch_classesObject



83
84
85
# File 'lib/maglev_record/snapshot/change.rb', line 83

def superclass_mismatch_classes
  []
end