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