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 = {}) ⇒ 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.
86 87 88 89 |
# File 'lib/active_fedora/datastreams.rb', line 86 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
33 34 35 36 37 38 39 40 41 |
# File 'lib/active_fedora/datastreams.rb', line 33 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
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/active_fedora/datastreams.rb', line 118 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
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/active_fedora/datastreams.rb', line 55 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 = {}) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/active_fedora/datastreams.rb', line 137 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 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 || "" ds end |
#datastream_from_spec(ds_spec, name) ⇒ Object
66 67 68 |
# File 'lib/active_fedora/datastreams.rb', line 66 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.
51 52 53 |
# File 'lib/active_fedora/datastreams.rb', line 51 def datastreams @datastreams ||= DatastreamHash.new(self) end |
#ds_specs ⇒ Object
24 25 26 |
# File 'lib/active_fedora/datastreams.rb', line 24 def ds_specs self.class.ds_specs end |
#load_datastreams ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/active_fedora/datastreams.rb', line 70 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.
92 93 94 |
# File 'lib/active_fedora/datastreams.rb', line 92 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
101 102 103 104 105 106 107 108 |
# File 'lib/active_fedora/datastreams.rb', line 101 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
28 29 30 |
# File 'lib/active_fedora/datastreams.rb', line 28 def serialize_datastreams datastreams.each {|k, ds| ds.serialize! } end |