lib/hydra/generic_content.rb in hydra-head-4.0.3 vs lib/hydra/generic_content.rb in hydra-head-4.1.0

- old
+ new

@@ -1,11 +1,14 @@ # require "hydra" # require "httparty" # require "mime/types" # will move to lib/hydra/model/generic_content_behavior in release 5.x +require 'deprecation' module Hydra::GenericContent + extend Deprecation + self.deprecation_horizon = 'hydra-head 5.x' def self.included(klass) klass.send :include, Hydra::ModelMethods end @@ -25,18 +28,21 @@ DEFAULT_CONTENT_DATASTREAMS.each do |m| class_eval <<-EOM def has_#{m}? self.datastreams.keys.include? "#{m}" end + deprecation_deprecate :has_#{m}? def #{m} datastreams["#{m}"].content if has_#{m}? end + deprecation_deprecate :#{m} def #{m}=(file) create_or_update_datastream( "#{m}", file ) end + deprecation_deprecate :#{m}= EOM end private @@ -44,24 +50,27 @@ puts "creating datastream object for: #{url}" ds = ActiveFedora::Datastream.new(:dsid=> ds_name, :label => ds_name, :controlGroup => "M", :dsLocation => url, :mimeType=>mime_type(url.split(/\//).last)) add_datastream(ds) save end + deprecation_deprecate :from_url def from_binary binary_info, ds_name file = binary_to_file(binary_info[:blob],ds_name,binary_info[:extension]) add_file_datastream(file,:dsid=>ds_name,:label=>ds_name) save end + deprecation_deprecate :from_binary def binary_to_file blob, suffix, ext=nil file_name = Time.now.strftime("%Y%m%d-%H%M%S") f = File.new("#{Rails.root}/tmp/#{file_name}-#{suffix}.#{ext}","w") f.write blob f.close return f end + deprecation_deprecate :binary_to_file def create_or_update_datastream ds_name, file case file when File logger.debug "adding #{ds_name} file datastream" @@ -74,10 +83,11 @@ elsif file.has_key? :file add_file_datastream(file[:file], :dsid => ds_name, :label => ds_name, :mimeType => mime_type(file[:file_name])) end end end + deprecation_deprecate :create_or_update_datastream # Returns a human readable filesize appropriate for the given number of bytes (ie. automatically chooses 'bytes','KB','MB','GB','TB') # Based on a bit of python code posted here: http://blogmag.net/blog/read/38/Print_human_readable_file_size # @param [Numeric] num file size in bits def bits_to_human_readable(num) @@ -87,13 +97,15 @@ else num = num/1024.0 end end end + deprecation_deprecate :bits_to_human_readable # augments add_file_datastream to also put file size (in bytes/KB/MB/GB/TB) in mods:physicaldescription/mods:extent def add_file_datastream(file, opts={}) + Deprecation.warn(Hydra::GenericContent, "add_file_datastream is deprecated and will be removed in hydra-head 5.x") # label = opts.has_key?(:label) ? opts[:label] : "" # mimeType = opts.has_key?(:mimeType) ? opts[:mimeType] : "" # ds = ActiveFedora::Datastream.new(:dsLabel => label, :controlGroup => 'M', :blob => file, :mimeType => mimeType) # opts.has_key?(:dsid) ? ds.dsid=(opts[:dsid]) : nil # add_datastream(ds) @@ -105,11 +117,14 @@ else size = "" end descMetadata.update_indexed_attributes( [:physical_description, :extent] => size ) end + # deprecation_deprecate :add_file_datastream ## 'super' call breaks under ree.. ?? def mime_type file_name mime_types = MIME::Types.of(file_name) mime_type = mime_types.empty? ? "application/octet-stream" : mime_types.first.content_type end + deprecation_deprecate :mime_type + end