32 lines
954 B
Ruby
32 lines
954 B
Ruby
module JamRuby
|
|
class ArtifactUpdate < ActiveRecord::Base
|
|
|
|
DEFAULT_ENVIRONMENT = 'public'
|
|
|
|
PRODUCTS = ['JamClient/Win32', 'JamClient/MacOSX']
|
|
|
|
self.primary_key = 'id'
|
|
attr_accessible :version, :uri, :sha1, :environment, :product
|
|
|
|
# ORDER MATTERS HERE- before_save for this method must be declared before mount_uploader: https://github.com/jnicklas/carrierwave/wiki/Known-Issues
|
|
before_save :update_uri_attributes
|
|
mount_uploader :uri, ArtifactUploader
|
|
|
|
validate :version, :presence => true
|
|
validate :uri, :presence => true
|
|
validate :sha1, :presence => true
|
|
validate :size, :presence => true
|
|
validate :environment, :presence => true
|
|
validate :product, :inclusion => {:in => PRODUCTS}
|
|
|
|
private
|
|
|
|
def update_uri_attributes
|
|
if uri.present? && uri_changed?
|
|
self.size = uri.file.size
|
|
self.sha1 = Digest::MD5.hexdigest(File.read(uri.current_path))
|
|
end
|
|
end
|
|
end
|
|
end
|