Module: SoftwareHeretics::ActiveRecord::SimplyVersioned::VersionsProxyMethods

Defined in:
lib/simply_versioned.rb

Instance Method Summary collapse

Instance Method Details

#clean_old_versions(versions_to_keep) ⇒ Object Also known as: purge

If the model instance has more versions than the limit specified, delete all excess older versions.



198
199
200
201
202
# File 'lib/simply_versioned.rb', line 198

def clean_old_versions( versions_to_keep )
  find( :all, :conditions => [ 'number <= ?', self.maximum( :number ) - versions_to_keep ] ).each do |version|
    version.destroy
  end
end

#current_versionObject Also known as: current

Get the current Version corresponding to this model.



192
193
194
# File 'lib/simply_versioned.rb', line 192

def current_version
  find( :first, :order => 'number DESC' )
end

#first_versionObject Also known as: first

Get the first Version corresponding to this model.



186
187
188
# File 'lib/simply_versioned.rb', line 186

def first_version
  find( :first, :order => 'number ASC' )
end

#get_version(number) ⇒ Object Also known as: get

Get the Version instance corresponding to this models for the specified version number.



180
181
182
# File 'lib/simply_versioned.rb', line 180

def get_version( number )
  find_by_number( number )
end

#next_version(number) ⇒ Object Also known as: next

Return the Version for this model with the next higher version



206
207
208
# File 'lib/simply_versioned.rb', line 206

def next_version( number )
  find( :first, :order => 'number ASC', :conditions => [ "number > ?", number ] )
end

#previous_version(number) ⇒ Object Also known as: previous

Return the Version for this model with the next lower version



212
213
214
# File 'lib/simply_versioned.rb', line 212

def previous_version( number )
  find( :first, :order => 'number DESC', :conditions => [ "number < ?", number ] )
end