Module: ActiveFedora::Datastreams
- Extended by:
- ActiveSupport::Concern
- Included in:
- Base
- Defined in:
- lib/active_fedora/datastreams.rb,
lib/active_fedora/datastreams/nokogiri_datastreams.rb
Defined Under Namespace
Modules: ClassMethods, NokogiriDatastreams
Instance Method Summary collapse
-
#add_datastream(datastream, opts = {}) ⇒ String
Adds datastream to the object.
-
#add_disseminator_location_to_datastreams ⇒ Object
Adds the disseminator location to the datastream after the pid has been established.
-
#add_file_datastream(file, opts = {}) ⇒ Object
Add the given file as a datastream in the object.
- #configure_datastream(ds, ds_spec = nil) ⇒ Object
-
#create_datastream(type, dsid, opts = {}) ⇒ ActiveFedora::Datastream
Creates a datastream to be added to the object.
- #datastream_from_spec(ds_spec, name) ⇒ Object
-
#datastreams ⇒ Object
Returns all known datastreams for the object.
- #ds_specs ⇒ Object
- #load_datastreams ⇒ Object
-
#metadata_streams ⇒ Array
All datastreams that return true for ‘metadata?` and are not Rels-ext.
-
#rels_ext ⇒ Object
Returns the RELS-EXT Datastream Tries to grab from in-memory datastreams first Failing that, attempts to load from Fedora and addst to in-memory datastreams Failing that, creates a new RelsExtDatastream and adds it to the object.
- #serialize_datastreams ⇒ Object
Instance Method Details
#add_datastream(datastream, opts = {}) ⇒ String
Adds datastream to the object.
84 85 86 87 |
# File 'lib/active_fedora/datastreams.rb', line 84 def add_datastream(datastream, opts={}) datastreams[datastream.dsid] = datastream datastream.dsid end |
#add_disseminator_location_to_datastreams ⇒ Object
Adds the disseminator location to the datastream after the pid has been established
31 32 33 34 35 36 37 38 39 |
# File 'lib/active_fedora/datastreams.rb', line 31 def add_disseminator_location_to_datastreams self.ds_specs.each do |name,ds_config| ds = datastreams[name] if ds && ds.controlGroup == 'E' && ds_config[:disseminator].present? ds.dsLocation= "#{ActiveFedora.config_for_environment[:url]}/objects/#{pid}/methods/#{ds_config[:disseminator]}" end end true end |
#add_file_datastream(file, opts = {}) ⇒ Object
Add the given file as a datastream in the object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/active_fedora/datastreams.rb', line 116 def add_file_datastream(file, opts={}) label = opts.has_key?(:label) ? opts[:label] : "" attrs = {:dsLabel => label, :controlGroup => 'M', :blob => file, :prefix=>opts[:prefix]} if opts.has_key?(:mime_type) attrs.merge!({:mimeType=>opts[:mime_type]}) elsif opts.has_key?(:mimeType) attrs.merge!({:mimeType=>opts[:mimeType]}) elsif opts.has_key?(:content_type) attrs.merge!({:mimeType=>opts[:content_type]}) end attrs[:checksumType] = opts[:checksumType] if opts[:checksumType] attrs[:versionable] = opts[:versionable] unless opts[:versionable].nil? ds = create_datastream(self.class.datastream_class_for_name(opts[:dsid]), opts[:dsid], attrs) add_datastream(ds).tap do |dsid| self.class.build_datastream_accessor(dsid) unless respond_to? dsid end end |
#configure_datastream(ds, ds_spec = nil) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/active_fedora/datastreams.rb', line 53 def configure_datastream(ds, ds_spec=nil) ds_spec ||= self.ds_specs[ds.dsid] if ds_spec ds.model = self if ds_spec[:type] == RelsExtDatastream # If you called has_metadata with a block, pass the block into the Datastream class if ds_spec[:block].class == Proc ds_spec[:block].call(ds) end end end |
#create_datastream(type, dsid, opts = {}) ⇒ ActiveFedora::Datastream
Creates a datastream to be added to the object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/active_fedora/datastreams.rb', line 140 def create_datastream(type, dsid, opts={}) klass = type.kind_of?(Class) ? type : type.constantize raise ArgumentError, "Argument dsid must be of type string" if dsid && !dsid.kind_of?(String) ds = klass.new(inner_object, dsid, prefix: opts[:prefix]) [:mimeType, :controlGroup, :dsLabel, :dsLocation, :checksumType, :versionable].each do |key| ds.send("#{key}=".to_sym, opts[key]) unless opts[key].nil? end if ds.managed? || ds.inline? blob = opts[:blob] if blob if !ds.mimeType.present? ##TODO, this is all done by rubydora -- remove ds.mimeType = blob.respond_to?(:content_type) ? blob.content_type : "application/octet-stream" end if !ds.dsLabel.present? && blob.respond_to?(:path) ds.dsLabel = File.basename(blob.path) end end ds.content = blob || "" end ds end |
#datastream_from_spec(ds_spec, name) ⇒ Object
64 65 66 |
# File 'lib/active_fedora/datastreams.rb', line 64 def datastream_from_spec(ds_spec, name) inner_object.datastream_object_for name, {}, ds_spec end |
#datastreams ⇒ Object
Returns all known datastreams for the object. If the object has been saved to fedora, the persisted datastreams will be included. Datastreams that have been modified in memory are given preference over the copy in Fedora.
49 50 51 |
# File 'lib/active_fedora/datastreams.rb', line 49 def datastreams @datastreams ||= DatastreamHash.new(self) end |
#ds_specs ⇒ Object
22 23 24 |
# File 'lib/active_fedora/datastreams.rb', line 22 def ds_specs self.class.ds_specs end |
#load_datastreams ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/active_fedora/datastreams.rb', line 68 def load_datastreams local_ds_specs = self.ds_specs.dup inner_object.datastreams.each do |dsid, ds| self.add_datastream(ds) configure_datastream(datastreams[dsid]) local_ds_specs.delete(dsid) end local_ds_specs.each do |name,ds_spec| ds = datastream_from_spec(ds_spec, name) self.add_datastream(ds) configure_datastream(ds, ds_spec) end end |
#metadata_streams ⇒ Array
Returns all datastreams that return true for ‘metadata?` and are not Rels-ext.
90 91 92 |
# File 'lib/active_fedora/datastreams.rb', line 90 def datastreams.select { |k, ds| ds. }.reject { |k, ds| ds.kind_of?(ActiveFedora::RelsExtDatastream) }.values end |
#rels_ext ⇒ Object
Returns the RELS-EXT Datastream Tries to grab from in-memory datastreams first Failing that, attempts to load from Fedora and addst to in-memory datastreams Failing that, creates a new RelsExtDatastream and adds it to the object
99 100 101 102 103 104 105 106 |
# File 'lib/active_fedora/datastreams.rb', line 99 def rels_ext if !datastreams.has_key?("RELS-EXT") ds = ActiveFedora::RelsExtDatastream.new(@inner_object,'RELS-EXT') ds.model = self add_datastream(ds) end return datastreams["RELS-EXT"] end |
#serialize_datastreams ⇒ Object
26 27 28 |
# File 'lib/active_fedora/datastreams.rb', line 26 def serialize_datastreams datastreams.each {|k, ds| ds.serialize! } end |