ontology_version.rb revision b0779279f704973922208157bb41a4c1569ce356
0075dcb5aeeee4864fe9f64db82c8a8202bbe6d6henning muellerclass OntologyVersion < ActiveRecord::Base
87107747f8a51d0f07c2e2a415fcf9c494783f0fhenning mueller include OntologyVersion::Async
87107747f8a51d0f07c2e2a415fcf9c494783f0fhenning mueller include OntologyVersion::Download
9c9b4f0d0199c3b1dbff564b87435b6693b7e692Julian Kornberger include OntologyVersion::Parsing
7ea9649883e1bbe8f2582db1a3c66af8b7206056henning mueller
0075dcb5aeeee4864fe9f64db82c8a8202bbe6d6henning mueller belongs_to :user
cbb18f95cb8354f0c3fb44ba5134dadc7ad6b2ecJulian Kornberger belongs_to :ontology, :counter_cache => :versions_count
3cd45197413df1ff1401697720f1ac9ccef8f8eehenning mueller
3cd45197413df1ff1401697720f1ac9ccef8f8eehenning mueller mount_uploader :raw_file, OntologyUploader
3cd45197413df1ff1401697720f1ac9ccef8f8eehenning mueller mount_uploader :xml_file, OntologyUploader
ec96c6e3605c2e9eb5c0113e4e1b07b3b5228c8chenning mueller
87107747f8a51d0f07c2e2a415fcf9c494783f0fhenning mueller attr_accessible :raw_file, :source_uri
d12cf3a51e30d69a53108694ba68ba584942dbb8henning mueller
ffa89afcecb07f2fe8664d097cc6839d1d22d7dbhenning mueller validate :raw_file_xor_source_uri, :on => :create
b0779279f704973922208157bb41a4c1569ce356henning mueller# validate :raw_file_size_maximum
ecf32c9d659a1f42c730d61eaa93583c095a4fddhenning mueller
ecf32c9d659a1f42c730d61eaa93583c095a4fddhenning mueller validates_format_of :source_uri,
ecf32c9d659a1f42c730d61eaa93583c095a4fddhenning mueller :with => URI::regexp(ALLOWED_URI_SCHEMAS), :if => :source_uri?
0772cf7b22adf46dbab68e829d6a2cd8e8d1bc2ahenning mueller
432ee743a5f1c5688c73446b5977b06ed97fb67cJulian Kornberger scope :latest, order('id DESC')
7ea9649883e1bbe8f2582db1a3c66af8b7206056henning mueller
8d4d8ac34f199d5c7d26694fabbfe2ab6bc0f9d9henning muellerprotected
8d4d8ac34f199d5c7d26694fabbfe2ab6bc0f9d9henning mueller
87107747f8a51d0f07c2e2a415fcf9c494783f0fhenning mueller def raw_file_xor_source_uri
8d4d8ac34f199d5c7d26694fabbfe2ab6bc0f9d9henning mueller if !(raw_file.blank? ^ source_uri.blank?)
87107747f8a51d0f07c2e2a415fcf9c494783f0fhenning mueller errors.add :source_uri, 'Specify either a source file or URI.'
8d4d8ac34f199d5c7d26694fabbfe2ab6bc0f9d9henning mueller end
8d4d8ac34f199d5c7d26694fabbfe2ab6bc0f9d9henning mueller end
ecf32c9d659a1f42c730d61eaa93583c095a4fddhenning mueller
ecf32c9d659a1f42c730d61eaa93583c095a4fddhenning mueller def raw_file_size_maximum
ecf32c9d659a1f42c730d61eaa93583c095a4fddhenning mueller if raw_file.size > 10.megabytes.to_i
ecf32c9d659a1f42c730d61eaa93583c095a4fddhenning mueller errors.add :raw_file, 'The maximum file size is 10M.'
ecf32c9d659a1f42c730d61eaa93583c095a4fddhenning mueller end
ecf32c9d659a1f42c730d61eaa93583c095a4fddhenning mueller end
0075dcb5aeeee4864fe9f64db82c8a8202bbe6d6henning muellerend