Class: Ddr::Resource

Inherits:
Valkyrie::Resource
  • Object
show all
Includes:
Describable, Governable, HasAdminMetadata, HasThumbnail
Defined in:
app/models/ddr/resource.rb

Direct Known Subclasses

Attachment, Collection, Component, Item, Target

Constant Summary collapse

FILE_FIELDS =
%i( caption
content
derived_image
extracted_text
fits_file
intermediate_file
multires_image
streamable_media
struct_metadata
thumbnail
)

Constants included from HasAdminMetadata

HasAdminMetadata::TERMS

Constants included from Describable

Describable::TERM_NAMES

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HasThumbnail

#thumbnail_path

Methods included from HasAdminMetadata

#effective_permissions, #effective_roles, #finding_aid, #inherited_roles, #locked?, #nonpublishable?, #policy_roles, #published?, #research_help, #resource_roles, term_names, #unpublished?

Methods included from Governable

#admin_policy, #admin_policy=

Methods included from Describable

default_indexers, #desc_metadata_terms, #desc_metadata_vocabs, #has_desc_metadata?, indexers, indexers_for, #set_desc_metadata, #set_desc_metadata_values, term_names, vocabularies

Class Method Details

.attachable_filesObject



37
38
39
# File 'app/models/ddr/resource.rb', line 37

def self.attachable_files
  @attachable_files ||= FILE_FIELDS.select { |f| fields.include?(f) }
end

.can_be_streamable?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'app/models/ddr/resource.rb', line 49

def self.can_be_streamable?
  can_have_streamable_media?
end

.canonical_model_name(model_name) ⇒ Object



53
54
55
# File 'app/models/ddr/resource.rb', line 53

def self.canonical_model_name(model_name)
  model_name.starts_with?('Ddr::') ? model_name : "Ddr::#{model_name}"
end

.captionable?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'app/models/ddr/resource.rb', line 45

def self.captionable?
  can_have_caption?
end

.common_model_nameObject



57
58
59
# File 'app/models/ddr/resource.rb', line 57

def self.common_model_name
  name.split('::').last
end

.governable?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'app/models/ddr/resource.rb', line 41

def self.governable?
  fields.include? :admin_policy_id
end

.metadata_fieldsObject



61
62
63
# File 'app/models/ddr/resource.rb', line 61

def self.
  fields - FILE_FIELDS - reserved_attributes
end

.tableized_nameObject



65
66
67
# File 'app/models/ddr/resource.rb', line 65

def self.tableized_name
  name.tableize
end

Instance Method Details

#attached_files_having_contentObject



86
87
88
# File 'app/models/ddr/resource.rb', line 86

def attached_files_having_content
  attachable_files.select { |f| has_file?(f) }
end

#embargoObject

Embargoes are enforced by the ‘Embargoable` concern, which overrides the `embargo` and `embargoed?` methods



103
104
105
# File 'app/models/ddr/resource.rb', line 103

def embargo
  nil
end

#embargoed?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'app/models/ddr/resource.rb', line 107

def embargoed?
  false
end

#has_admin_policy?Boolean

Returns:

  • (Boolean)


111
112
113
# File 'app/models/ddr/resource.rb', line 111

def has_admin_policy?
  governable? && admin_policy_id.present?
end

#has_file?(f) ⇒ Boolean

Returns:

  • (Boolean)


90
91
92
# File 'app/models/ddr/resource.rb', line 90

def has_file?(f)
  send(f)&.file_identifier.present?
end

#publishable?Boolean

By default, no resources are publishable. To enable publication of a particular class of resource, (1) include the ‘HasAdminMetadata` concern in the model class, which defines a `nonpublishable?` method which returns true if the workflow_state is “nonpublishable” and (2) override the `publishable?` method to provide the logic for determining if a particular resource is publishable.

Returns:

  • (Boolean)


98
99
100
# File 'app/models/ddr/resource.rb', line 98

def publishable?
  false
end

#rights_statementObject



75
76
77
# File 'app/models/ddr/resource.rb', line 75

def rights_statement
  RightsStatement.call(self)
end

#title_displayObject



79
80
81
82
83
84
# File 'app/models/ddr/resource.rb', line 79

def title_display
  return title.first if title.present?
  return identifier.first if identifier.present?
  return original_filename if respond_to?(:original_filename) && original_filename.present?
  "[#{id}]"
end

#values(term) ⇒ Object

Convenience method for retrieving values of a metadata term



119
120
121
# File 'app/models/ddr/resource.rb', line 119

def values(term)
  self.send(term)
end