Class: MaglevRecord::SuperclassMismatchChange
Instance Method Summary
collapse
#changes_since, #nothing_changed?, #superclass_mismatch_class_names, #superclass_mismatch_classes
Constructor Details
Returns a new instance of SuperclassMismatchChange.
35
36
37
38
|
# File 'lib/maglev_record/snapshot/superclass_mismatch_change.rb', line 35
def initialize(cls, file_path)
@cls = cls
@file_path = file_path
end
|
Instance Method Details
#class_name ⇒ Object
methods for the single change
89
90
91
|
# File 'lib/maglev_record/snapshot/superclass_mismatch_change.rb', line 89
def class_name
mismatching_class.name
end
|
#determine_new_superclass ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/maglev_record/snapshot/superclass_mismatch_change.rb', line 52
def determine_new_superclass
constant_name = mismatching_class.name
class_to_replace = nil Maglev.persistent do
begin
class_to_replace = Object.remove_const constant_name
rescue NameError
return ClassWithMismatchNotFound.new
else
if class_to_replace != mismatching_class
Object.const_set constant_name, class_to_replace
return ClassWithMismatchNotFound.new
end
end
end
begin
Kernel.load file_path
cls = Object.const_get constant_name
return cls.superclass
ensure
Object.const_set constant_name, class_to_replace
end
end
|
#file_path ⇒ Object
40
41
42
|
# File 'lib/maglev_record/snapshot/superclass_mismatch_change.rb', line 40
def file_path
@file_path
end
|
#migration_string(identation = 0) ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/maglev_record/snapshot/superclass_mismatch_change.rb', line 44
def migration_string(identation = 0)
" " * identation + [
"# TypeError: superclass mismatch for #{class_name}",
"# in #{file_path}",
"#{class_name}.change_superclass_to #{new_superclass.name}"
].join("\n" + " " * identation)
end
|
#mismatching_class ⇒ Object
93
94
95
|
# File 'lib/maglev_record/snapshot/superclass_mismatch_change.rb', line 93
def mismatching_class
@cls
end
|
#new_superclass ⇒ Object
82
83
84
85
|
# File 'lib/maglev_record/snapshot/superclass_mismatch_change.rb', line 82
def new_superclass
@new_super_class = determine_new_superclass if @new_super_class.nil?
@new_super_class
end
|