Files

UbiquoVersions::Extensions::ActiveRecord::InstanceMethods

Public Class Methods

included(klass) click to toggle source

(Not documented)

     # File vendor/plugins/ubiquo_versions/lib/ubiquo_versions/extensions/active_record.rb, line 149
149:         def self.included(klass)
150:           klass.alias_method_chain :create, :version_info
151:           klass.alias_method_chain :update, :version
152:           klass.alias_method_chain :delete, :all_versions
153:           klass.alias_method_chain :destroy, :all_versions
154:         end

Public Instance Methods

create_new_version(add_version_number = false) click to toggle source

This function creates a new old version of the current instance by cloning it

     # File vendor/plugins/ubiquo_versions/lib/ubiquo_versions/extensions/active_record.rb, line 207
207:         def create_new_version(add_version_number = false)
208:           current_instance = self.class.find(self.id).clone
209:           current_instance.is_current_version = false
210:           current_instance.parent_version = self.id
211:           current_instance.version_number = next_version_number if add_version_number
212:           current_instance.save
213:           # delete the older versions if there are too many versions (as defined by max_amount)
214:           if max_amount = self.class.instance_variable_get('@versionable_options')[:max_amount]
215:             versions_by_number = self.versions.sort {|a,b| a.version_number <=> b.version_number}
216:             (versions_by_number.size - max_amount).times do |i|
217:               versions_by_number[i].delete
218:             end
219:           end
220:         end
create_version_for_other_current_versions() click to toggle source

This function looks for other instances sharing the same content_id and is_current_version = true, and creates a new version for them too. This is useful if for any reason you have more than one current version per content_id

     # File vendor/plugins/ubiquo_versions/lib/ubiquo_versions/extensions/active_record.rb, line 198
198:         def create_version_for_other_current_versions
199:           self.class.all(
200:             :conditions => ["content_id = ? AND is_current_version = ? AND id != ?", self.content_id, true, self.id || 0]
201:           ).each do |current_version|
202:             current_version.create_new_version(true)
203:           end
204:         end
create_with_version_info() click to toggle source

proxy to add a new content_id if empty on creation

     # File vendor/plugins/ubiquo_versions/lib/ubiquo_versions/extensions/active_record.rb, line 157
157:         def create_with_version_info
158:           if self.class.instance_variable_get('@versionable')
159:             if disable_versionable_once
160:               create_without_version_info
161:               return
162:             end
163:             unless self.content_id
164:               self.content_id = self.class.connection.next_val_sequence("#{self.class.table_name}_$_content_id")
165:             end
166:             unless self.version_number
167:               self.version_number = next_version_number
168:               self.is_current_version = true
169:             end
170:             create_without_version_info
171: 
172:             unless self.parent_version
173:               self.class.without_versionable {update_attribute :parent_version, self.id}
174:             end
175:           else
176:             create_without_version_info
177:           end
178:         end
delete_with_all_versions() click to toggle source

proxy to delete all the related versions on delete

     # File vendor/plugins/ubiquo_versions/lib/ubiquo_versions/extensions/active_record.rb, line 231
231:         def delete_with_all_versions
232:           if self.class.instance_variable_get('@versionable') && self.is_current_version
233:             self.versions.delete_all
234:           end
235:           delete_without_all_versions
236:         end
destroy_with_all_versions() click to toggle source

proxy to destroy all the related versions on destroy

     # File vendor/plugins/ubiquo_versions/lib/ubiquo_versions/extensions/active_record.rb, line 223
223:         def destroy_with_all_versions
224:           if self.class.instance_variable_get('@versionable') && self.is_current_version
225:             self.versions.destroy_all
226:           end
227:           destroy_without_all_versions
228:         end
disable_versionable_once() click to toggle source

This method disables versionable for one action

     # File vendor/plugins/ubiquo_versions/lib/ubiquo_versions/extensions/active_record.rb, line 239
239:         def disable_versionable_once
240:           if self.class.instance_variable_get('@versionable_disabled')
241:             self.class.instance_variable_set('@versionable_disabled', false)
242:             true
243:           end
244:         end
next_version_number() click to toggle source

Note that every time that is called, a version number is assigned

     # File vendor/plugins/ubiquo_versions/lib/ubiquo_versions/extensions/active_record.rb, line 247
247:         def next_version_number
248:           self.class.connection.next_val_sequence("#{self.class.table_name}_$_version_number")
249:         end
update_with_version() click to toggle source

proxy to add a create a new version when an update is performed

     # File vendor/plugins/ubiquo_versions/lib/ubiquo_versions/extensions/active_record.rb, line 181
181:         def update_with_version
182:           if self.class.instance_variable_get('@versionable') && self.changed?
183:             if disable_versionable_once
184:               update_without_version
185:               return
186:             end
187:             self.version_number = next_version_number
188:             create_new_version
189:             update_without_version
190:           else
191:             update_without_version
192:           end
193:         end

Disabled; run with $DEBUG to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.