Sha256: 987905e2110286858f569c15382063d2868fc5896d0fcc62be48c5dc66085442

Contents?: true

Size: 666 Bytes

Versions: 2

Compression:

Stored size: 666 Bytes

Contents

class Version < ActiveRecord::Base
  
  belongs_to :versioned, :polymorphic => true
  
  validates_presence_of :versioned, :changes, :number
  validates_numericality_of :number, :greater_than => 0, :only_integer => true
  validates_uniqueness_of :number, :scope => ['versioned_type', 'versioned_id']
  
  serialize :changes, Hash
  
  before_create :set_number
  
  def version
    number
  end
  
  def <=>(other)
    number <=> other.number
  end
  
  def <(other)
    number < other.number
  end
  
  def >(other)
    number > other.number
  end
  
  private
  
  def set_number
    write_attribute(:number, versioned.versions.maximum(:number).to_i + 1)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
laserlemon-vestal_versions-0.2.4 lib/version.rb
laserlemon-vestal_versions-0.2.5 lib/version.rb