Module: Hydra::ModelMethods
- Included in:
- ModsAsset
- Defined in:
- lib/hydra/model_methods.rb
Instance Method Summary collapse
-
#add_file(file, dsid, file_name) ⇒ Object
Puts the contents of file (posted blob) into a datastream and sets the title and label Sets asset label and title to filename if they’re empty.
-
#apply_depositor_metadata(depositor) ⇒ Object
Adds metadata about the depositor to the asset Most important behavior: if the asset has a rightsMetadata datastream, this method will add
depositor_id
to its individual edit permissions. -
#set_title(new_title, opts = {}) ⇒ Object
Set the title and label on the current object.
-
#set_title_and_label(new_title, opts = {}) ⇒ Object
Set the title and label on the current object.
Instance Method Details
#add_file(file, dsid, file_name) ⇒ Object
Puts the contents of file (posted blob) into a datastream and sets the title and label Sets asset label and title to filename if they’re empty
26 27 28 29 30 31 32 33 |
# File 'lib/hydra/model_methods.rb', line 26 def add_file(file, dsid, file_name) mime_types = MIME::Types.of(file_name) mime_type = mime_types.empty? ? "application/octet-stream" : mime_types.first.content_type = {:label=>file_name, :mimeType=>mime_type} [:dsid] = dsid if dsid add_file_datastream(file, ) set_title_and_label( file_name, :only_if_blank=>true ) end |
#apply_depositor_metadata(depositor) ⇒ Object
Adds metadata about the depositor to the asset Most important behavior: if the asset has a rightsMetadata datastream, this method will add depositor_id
to its individual edit permissions.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/hydra/model_methods.rb', line 8 def (depositor) prop_ds = self.datastreams["properties"] rights_ds = self.datastreams["rightsMetadata"] depositor_id = depositor.respond_to?(:user_key) ? depositor.user_key : depositor if prop_ds prop_ds.depositor = depositor_id unless prop_ds.nil? end rights_ds.({:person=>depositor_id}, 'edit') unless rights_ds.nil? return true end |
#set_title(new_title, opts = {}) ⇒ Object
Set the title and label on the current object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/hydra/model_methods.rb', line 60 def set_title(new_title, opts={}) if self.datastreams.has_key?("descMetadata") = self.datastreams["descMetadata"] if .respond_to?(:title_values) .title_values = new_title else .title = new_title end end end |
#set_title_and_label(new_title, opts = {}) ⇒ Object
Set the title and label on the current object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/hydra/model_methods.rb', line 44 def set_title_and_label(new_title, opts={}) if opts[:only_if_blank] if self.label.nil? || self.label.empty? self.label = new_title self.set_title( new_title ) end else self.label = new_title set_title( new_title ) end end |