Module: Hydra::ModelMethods
- Extended by:
- ActiveSupport::Concern
- Included in:
- ModsAsset
- Defined in:
- app/models/concerns/hydra/model_methods.rb
Instance Method Summary collapse
-
#add_file(file, path, file_name, mime_type = nil) ⇒ 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.
- #best_mime_for_filename(file_name) ⇒ Object
-
#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, path, file_name, mime_type = nil) ⇒ 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
16 17 18 19 20 21 22 |
# File 'app/models/concerns/hydra/model_methods.rb', line 16 def add_file(file, path, file_name, mime_type=nil) mime_type ||= best_mime_for_filename(file_name) = { mime_type: mime_type, original_name: file_name } [:path] = path if path super(file, ) set_title_and_label(file_name, only_if_blank: true) end |
#best_mime_for_filename(file_name) ⇒ Object
24 25 26 27 |
# File 'app/models/concerns/hydra/model_methods.rb', line 24 def best_mime_for_filename(file_name) mime_types = MIME::Types.of(file_name) mime_types.empty? ? "application/octet-stream" : mime_types.first.content_type end |
#set_title(new_title, opts = {}) ⇒ Object
Set the title and label on the current object
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/models/concerns/hydra/model_methods.rb', line 53 def set_title(new_title, opts={}) if respond_to? :title= self.title = self.class.multiple?(:title) ? Array(new_title) : new_title elsif attached_files.has_key?("descMetadata") Deprecation.warn ModelMethods, 'setting title in descMetadata is deprecated and will be remove in hydra-head 10.0. If you need this behavior declare `has_attribute :title`' if descMetadata.respond_to?(:title_values) descMetadata.title_values = new_title else descMetadata.title = new_title end end end |
#set_title_and_label(new_title, opts = {}) ⇒ Object
Set the title and label on the current object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/models/concerns/hydra/model_methods.rb', line 37 def set_title_and_label(new_title, opts={}) if opts[:only_if_blank] if respond_to?(:label) && label.blank? self.label = new_title set_title new_title end else self.label = new_title if respond_to? :label set_title new_title end end |