Module: MaglevRecord::Snapshotable::ClassMethods
- Defined in:
- lib/maglev_record/snapshot/snapshotable.rb
Instance Method Summary collapse
- #class_methods_not_to_snapshot ⇒ Object
- #class_methods_to_reset ⇒ Object
- #file_paths ⇒ Object
- #has_definitions? ⇒ Boolean
- #instance_methods_to_reset ⇒ Object
-
#reset ⇒ Object
resets the class to no methods returns a memento proc that can be called to restore the old state.
- #snapshot_class_methods ⇒ Object
- #snapshot_instance_methods ⇒ Object
- #without_methods ⇒ Object
Instance Method Details
#class_methods_not_to_snapshot ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/maglev_record/snapshot/snapshotable.rb', line 52 def class_methods_not_to_snapshot @class_methods_not_to_reset ||= [] # hackady hack! # welcome to the big ball of mud and the # "I do not know what goes on after hours trying"-architecture @class_methods_not_to_reset << "_validators" @class_methods_not_to_reset << "_validators=" @class_methods_not_to_reset << "_validators?" #@class_methods_not_to_reset << "method_missing" @class_methods_not_to_reset << methods(false).select{|m| m.include? "callback" } @class_methods_not_to_reset.flatten! @class_methods_not_to_reset.map!(&:to_s) @class_methods_not_to_reset.uniq! @class_methods_not_to_reset end |
#class_methods_to_reset ⇒ Object
76 77 78 |
# File 'lib/maglev_record/snapshot/snapshotable.rb', line 76 def class_methods_to_reset snapshot_class_methods end |
#file_paths ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/maglev_record/snapshot/snapshotable.rb', line 22 def file_paths (self.instance_methods(false).map { |m| self.instance_method(m).source_location.first } + self.methods(false).map { |m| self.method(m).source_location.first }).uniq end |
#has_definitions? ⇒ Boolean
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/maglev_record/snapshot/snapshotable.rb', line 30 def has_definitions? # In nested transaction this error occurs: # Error 2101, objId i52279553 does not exist, during transaction boundary fp = file_paths without_methods do fp.each{ |file_path| Kernel.load file_path if File.file? file_path } return !file_paths.empty? end end |
#instance_methods_to_reset ⇒ Object
80 81 82 |
# File 'lib/maglev_record/snapshot/snapshotable.rb', line 80 def instance_methods_to_reset snapshot_instance_methods end |
#reset ⇒ Object
resets the class to no methods returns a memento proc that can be called to restore the old state
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/maglev_record/snapshot/snapshotable.rb', line 88 def reset _instance_methods = instance_methods_to_reset.map { |m| meth = instance_method m remove_method m meth } _class_methods = class_methods_to_reset.map { |m| meth = method m singleton_class.remove_method m meth } return Proc.new { instance_methods_to_reset.each { |m| remove_method m } class_methods_to_reset.each{ |m| singleton_class.remove_method m } _instance_methods.each{|m| define_method m.name, m } _class_methods.each{|m| singleton_class.define_method m.name, m } self } end |
#snapshot_class_methods ⇒ Object
68 69 70 |
# File 'lib/maglev_record/snapshot/snapshotable.rb', line 68 def snapshot_class_methods methods(false) - class_methods_not_to_snapshot end |
#snapshot_instance_methods ⇒ Object
72 73 74 |
# File 'lib/maglev_record/snapshot/snapshotable.rb', line 72 def snapshot_instance_methods instance_methods(false).reject{|m| m.include? 'callback' or m.include? 'valid'} end |
#without_methods ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/maglev_record/snapshot/snapshotable.rb', line 42 def without_methods return unless block_given? memento = reset begin yield ensure memento.call end end |