ontology_version.rb revision b0ad67a7b41855a9148f346eb5b5d2b9276796dd
1516N/Aclass OntologyVersion < ActiveRecord::Base
38N/A
38N/A include OntologyVersion::Files
38N/A include OntologyVersion::States
38N/A include OntologyVersion::Parsing
38N/A include OntologyVersion::Numbers
38N/A include OntologyVersion::OopsRequests
38N/A
38N/A include Rails.application.routes.url_helpers
38N/A include ActionDispatch::Routing::UrlFor
38N/A
38N/A belongs_to :user
38N/A belongs_to :ontology, :counter_cache => :versions_count
38N/A
38N/A# before_validation :set_checksum
38N/A# validate :raw_file_size_maximum
38N/A
38N/A validates_format_of :source_url,
38N/A :with => URI::regexp(Settings.allowed_iri_schemes), :if => :source_url?
38N/A
38N/A scope :latest, order('id DESC')
38N/A scope :done, state('done')
38N/A scope :failed, state('failed')
2276N/A
38N/A delegate :repository, to: :ontology
38N/A
38N/A # updated_at of the latest version
42N/A def self.last_updated_at
38N/A latest.first.try(:updated_at)
443N/A end
49N/A
49N/A def to_param
38N/A self.number
38N/A end
1955N/A
38N/A # Public URL to this version
50N/A #
50N/A # TODO: This returns a path without the commit id and filename for now,
38N/A # because the FilesController or the routes were not supporting it.
2276N/A def url(params={})
38N/A #Rails.application.routes.url_helpers.repository_ref_path(repository, commit_oid, ontology.path, params.reverse_merge(host: Settings.hostname, only_path: false))
38N/A url_for [repository, ontology, self]
38N/A end
38N/A
38N/A def default_url_options
38N/A {host: Settings.hostname}
49N/A end
49N/A
49N/A
49N/A protected
49N/A
443N/A def raw_file_size_maximum
443N/A if raw_file.size > 10.megabytes.to_i
443N/A errors.add :raw_file, 'The maximum file size is 10M.'
443N/A end
49N/A end
49N/A
443N/A def refresh_checksum!
443N/A self.checksum = Digest::SHA1.file(raw_path!).hexdigest
443N/A save! if checksum_changed?
1196N/A end
1196N/A
1196N/Aend
1196N/A