ontology_version.rb revision 46dd7ca898be6d5dbdfda64fd90ce01e253c0878
0075dcb5aeeee4864fe9f64db82c8a8202bbe6d6henning muellerclass OntologyVersion < ActiveRecord::Base
aead985e48027c9df1ef553b17df29dd378757aaJulian Kornberger include OntologyVersion::Files
5cad3e82e8c017bc189c4cecc00541ec19a2a6e2Julian Kornberger include OntologyVersion::States
9c9b4f0d0199c3b1dbff564b87435b6693b7e692Julian Kornberger include OntologyVersion::Parsing
b2dbef8c73faa240d208f3ff9fb49b21d9a894a5Daniel Vale include OntologyVersion::Numbers
dda6f544eb58d850394073e34ae6127498869a77Christian Clausen include OntologyVersion::OopsRequests
dda6f544eb58d850394073e34ae6127498869a77Christian Clausen
0075dcb5aeeee4864fe9f64db82c8a8202bbe6d6henning mueller belongs_to :user
cbb18f95cb8354f0c3fb44ba5134dadc7ad6b2ecJulian Kornberger belongs_to :ontology, :counter_cache => :versions_count
3cd45197413df1ff1401697720f1ac9ccef8f8eehenning mueller
ac2169141f0b549fc8917a4b1d778f4ba3cab0bfJulian Kornberger# before_validation :set_checksum
22e260fcd85642794d99c2ffaa333f2ef6ed7828Daniel Couto Vale# validate :raw_file_size_maximum
ecf32c9d659a1f42c730d61eaa93583c095a4fddhenning mueller
a14e1ccbd2588441fb5a59e0c82f895b5c42c298Julian Kornberger validates_format_of :source_url,
555b7fd96768daf9592e7ddbd4217d784b08e451henning mueller :with => URI::regexp(Settings.allowed_iri_schemes), :if => :source_url?
0772cf7b22adf46dbab68e829d6a2cd8e8d1bc2ahenning mueller
432ee743a5f1c5688c73446b5977b06ed97fb67cJulian Kornberger scope :latest, order('id DESC')
b9f99a06294e593ce8fb34b015e83003229db058Julian Kornberger scope :state, ->(state) { where :state => state }
b9f99a06294e593ce8fb34b015e83003229db058Julian Kornberger scope :done, state('done')
b3b159fb3284b66d0f8189a6a145c8163ccdae68henning mueller scope :failed, state('failed')
7ea9649883e1bbe8f2582db1a3c66af8b7206056henning mueller
a5015ca9daa067f062e9e373c3dfafd5631560d9Julian Kornberger delegate :repository, to: :ontology
a5015ca9daa067f062e9e373c3dfafd5631560d9Julian Kornberger
631f43db46ad7d375010c3169c81764eb27270a3Julian Kornberger # updated_at of the latest version
631f43db46ad7d375010c3169c81764eb27270a3Julian Kornberger def self.last_updated_at
631f43db46ad7d375010c3169c81764eb27270a3Julian Kornberger latest.first.try(:updated_at)
631f43db46ad7d375010c3169c81764eb27270a3Julian Kornberger end
631f43db46ad7d375010c3169c81764eb27270a3Julian Kornberger
ae2ba7aeef036808e81fb6449e98ce9abb0fb234Daniel Couto Vale def to_param
7dc318cbd9f8c97406b48051005f23953e9e8a25Daniel Vale self.number
ae2ba7aeef036808e81fb6449e98ce9abb0fb234Daniel Couto Vale end
43a0f914166a28a9d7f75ab10673dce129cb38a9Julian Kornberger
43a0f914166a28a9d7f75ab10673dce129cb38a9Julian Kornberger # public URL to this version
43a0f914166a28a9d7f75ab10673dce129cb38a9Julian Kornberger def url(params={})
46dd7ca898be6d5dbdfda64fd90ce01e253c0878Julian Kornberger Rails.application.routes.url_helpers.repository_ref_path(repository, commit_oid, ontology.path, params.reverse_merge(host: Settings.hostname, only_path: false))
43a0f914166a28a9d7f75ab10673dce129cb38a9Julian Kornberger end
acb3db0ee20cd276e305da358a03b30666976db0Daniel Couto Vale
8d4d8ac34f199d5c7d26694fabbfe2ab6bc0f9d9henning muellerprotected
8d4d8ac34f199d5c7d26694fabbfe2ab6bc0f9d9henning 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
1b6021653a43264993b21ebb20e0119aa2fd6741henning mueller
1b6021653a43264993b21ebb20e0119aa2fd6741henning mueller def set_checksum
1b6021653a43264993b21ebb20e0119aa2fd6741henning mueller self.checksum = raw_file.sha1 if raw_file.present? and raw_file_changed?
1b6021653a43264993b21ebb20e0119aa2fd6741henning mueller end
0075dcb5aeeee4864fe9f64db82c8a8202bbe6d6henning muellerend