Module: SoftwareHeretics::ActiveRecord::SimplyVersioned::VersionsProxyMethods
- Defined in:
- lib/simply_versioned.rb
Instance Method Summary collapse
-
#clean_old_versions(versions_to_keep) ⇒ Object
(also: #purge)
If the model instance has more versions than the limit specified, delete all excess older versions.
-
#current_version ⇒ Object
(also: #current)
Get the current Version corresponding to this model.
-
#first_version ⇒ Object
(also: #first)
Get the first Version corresponding to this model.
-
#get_version(number) ⇒ Object
(also: #get)
Get the Version instance corresponding to this models for the specified version number.
-
#next_version(number) ⇒ Object
(also: #next)
Return the Version for this model with the next higher version.
-
#previous_version(number) ⇒ Object
(also: #previous)
Return the Version for this model with the next lower version.
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_version ⇒ Object 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_version ⇒ Object 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 |