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