Class: FileVersion

Inherits:
Sequel::Model
  • Object
show all
Defined in:
backend/app/model/file_version.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.handle_publish_flag(ids, val) ⇒ Object



12
13
14
# File 'backend/app/model/file_version.rb', line 12

def self.handle_publish_flag(ids, val)
  ASModel.update_publish_flag(self.filter(:id => ids), val)
end

.sequel_to_jsonmodel(objs, opts = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'backend/app/model/file_version.rb', line 18

def self.sequel_to_jsonmodel(objs, opts = {})
  jsons = super

  jsons.zip(objs).each do |json, obj|
    json["identifier"] = obj[:id].to_s
  end

  jsons
end

Instance Method Details

#representative_for_typesObject



8
9
10
# File 'backend/app/model/file_version.rb', line 8

def representative_for_types
  { is_representative: [:digital_object, :digital_object_component] }
end

#validateObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'backend/app/model/file_version.rb', line 28

def validate
  is_published = false
  if self[:publish] == true || self[:publish] == 1
    is_published = true
  end

  is_representative = false
  if self[:is_representative] == true || self[:is_representative] == 1
    is_representative = true
  end

  if !is_published && is_representative
    errors.add(:is_representative, 'representative_file_version_must_be_published')
  end

  super
end