Module: VersionFu::InstanceMethods
- Defined in:
- lib/version_fu.rb
Instance Method Summary collapse
- #as_of_version(version) ⇒ Object
- #check_for_new_version ⇒ Object
-
#create_new_version? ⇒ Boolean
This the method to override if you want to have more control over when to version.
- #find_version(number) ⇒ Object
- #instatiate_revision ⇒ Object
- #revert ⇒ Object
- #revert_to(version) ⇒ Object
Instance Method Details
#as_of_version(version) ⇒ Object
117 118 119 120 121 122 123 124 125 |
# File 'lib/version_fu.rb', line 117 def as_of_version(version) v = find_version(version) obj = self.class.new (versioned_columns + [:version, :updated_at]).each do |a| obj.send("#{a}=", v.send(a)) end obj.id = id obj.freeze end |
#check_for_new_version ⇒ Object
84 85 86 87 |
# File 'lib/version_fu.rb', line 84 def check_for_new_version instatiate_revision if create_new_version? true # Never halt save end |
#create_new_version? ⇒ Boolean
This the method to override if you want to have more control over when to version
90 91 92 93 |
# File 'lib/version_fu.rb', line 90 def create_new_version? # Any versioned column changed? self.class.versioned_columns.detect {|a| __send__ "#{a}_changed?"} end |
#find_version(number) ⇒ Object
80 81 82 |
# File 'lib/version_fu.rb', line 80 def find_version(number) versions.find :first, :conditions=>{:version=>number} end |
#instatiate_revision ⇒ Object
95 96 97 98 99 100 101 102 103 |
# File 'lib/version_fu.rb', line 95 def instatiate_revision new_version = versions.build versioned_columns.each do |attribute| new_version.__send__ "#{attribute}=", __send__(attribute) end version_number = new_record? ? 1 : version + 1 new_version.version = version_number self.version = version_number end |
#revert ⇒ Object
105 106 107 |
# File 'lib/version_fu.rb', line 105 def revert revert_to(version-1) unless version == 1 end |
#revert_to(version) ⇒ Object
109 110 111 112 113 114 115 |
# File 'lib/version_fu.rb', line 109 def revert_to(version) revert_to_version = find_version(version) versioned_columns.each do |a| send("#{a}=", revert_to_version.send(a)) end save end |