Class: ActiveFedora::Datastream
- Inherits:
-
Fedora::Datastream
- Object
- Fedora::BaseObject
- Fedora::Datastream
- ActiveFedora::Datastream
- Defined in:
- lib/active_fedora/datastream.rb
Overview
This class represents a Fedora datastream
Direct Known Subclasses
Instance Attribute Summary collapse
-
#dirty ⇒ Object
Returns the value of attribute dirty.
-
#fields ⇒ Object
Returns the value of attribute fields.
-
#last_modified ⇒ Object
Returns the value of attribute last_modified.
Attributes inherited from Fedora::BaseObject
#attributes, #blob, #errors, #new_object, #uri
Class Method Summary collapse
- .delete(parent_pid, dsid) ⇒ Object
-
.from_xml(tmpl, node) ⇒ Object
Populate a Datastream object based on the “datastream” node from a FOXML file.
Instance Method Summary collapse
-
#after_save ⇒ Object
Callback.
-
#before_save ⇒ Object
Callback.
-
#check_concurrency ⇒ Object
:nodoc:.
-
#content ⇒ Object
Return the xml content representing this Datastream from Fedora.
-
#content=(content) ⇒ Object
set this Datastream’s content.
- #delete ⇒ Object
-
#dirty? ⇒ Boolean
Test whether this datastream been modified since it was last saved?.
-
#dsid=(dsid) ⇒ Object
set this datastreams identifier (note: sets both dsID and dsid).
-
#initialize(attrs = {}) ⇒ Datastream
constructor
A new instance of Datastream.
-
#last_modified_in_repository ⇒ Object
returns a datetime in the standard W3C DateTime Format.
-
#pid ⇒ Object
get this datastreams identifier.
-
#pid=(pid) ⇒ Object
set this datastreams parent identifier.
-
#save ⇒ Object
Save the datastream into fedora.
- #size ⇒ Object
-
#to_param ⇒ Object
compatibility method for rails’ url generators.
Methods inherited from Fedora::Datastream
#control_group, #control_group=, #dsid, #label, #label=, #mime_type, #mime_type=, #uri, #url
Methods inherited from Fedora::BaseObject
Constructor Details
#initialize(attrs = {}) ⇒ Datastream
Returns a new instance of Datastream.
9 10 11 12 13 |
# File 'lib/active_fedora/datastream.rb', line 9 def initialize(attrs = {}) @fields={} @dirty = false super end |
Instance Attribute Details
#dirty ⇒ Object
Returns the value of attribute dirty.
7 8 9 |
# File 'lib/active_fedora/datastream.rb', line 7 def dirty @dirty end |
#fields ⇒ Object
Returns the value of attribute fields.
7 8 9 |
# File 'lib/active_fedora/datastream.rb', line 7 def fields @fields end |
#last_modified ⇒ Object
Returns the value of attribute last_modified.
7 8 9 |
# File 'lib/active_fedora/datastream.rb', line 7 def last_modified @last_modified end |
Class Method Details
.delete(parent_pid, dsid) ⇒ Object
27 28 29 |
# File 'lib/active_fedora/datastream.rb', line 27 def self.delete(parent_pid, dsid) Fedora::Repository.instance.delete("%s/datastreams/%s"%[parent_pid, dsid]) end |
.from_xml(tmpl, node) ⇒ Object
Populate a Datastream object based on the “datastream” node from a FOXML file
92 93 94 95 96 |
# File 'lib/active_fedora/datastream.rb', line 92 def self.from_xml(tmpl, node) tmpl.instance_variable_set(:@dirty, false) tmpl.control_group= node['CONTROL_GROUP'] tmpl end |
Instance Method Details
#after_save ⇒ Object
Callback. Override this to insert behaviors after the save method. By default, sets self.dirty = false
99 100 101 |
# File 'lib/active_fedora/datastream.rb', line 99 def after_save self.dirty = false end |
#before_save ⇒ Object
Callback. Does nothing by default. Override this to insert behaviors before the save method.
85 86 87 |
# File 'lib/active_fedora/datastream.rb', line 85 def before_save #check_concurrency end |
#check_concurrency ⇒ Object
:nodoc:
126 127 128 |
# File 'lib/active_fedora/datastream.rb', line 126 def check_concurrency # :nodoc: return true end |
#content ⇒ Object
Return the xml content representing this Datastream from Fedora
16 17 18 19 |
# File 'lib/active_fedora/datastream.rb', line 16 def content result = Fedora::Repository.instance.fetch_custom(self.attributes[:pid], "datastreams/#{self.dsid}/content") return result end |
#content=(content) ⇒ Object
set this Datastream’s content
22 23 24 25 |
# File 'lib/active_fedora/datastream.rb', line 22 def content=(content) self.blob = content self.dirty = true end |
#delete ⇒ Object
31 32 33 |
# File 'lib/active_fedora/datastream.rb', line 31 def delete self.class.delete(self.pid, self.dsid) end |
#dirty? ⇒ Boolean
Test whether this datastream been modified since it was last saved?
71 72 73 |
# File 'lib/active_fedora/datastream.rb', line 71 def dirty? @dirty end |
#dsid=(dsid) ⇒ Object
set this datastreams identifier (note: sets both dsID and dsid)
46 47 48 49 |
# File 'lib/active_fedora/datastream.rb', line 46 def dsid=(dsid) self.attributes[:dsID] = dsid self.attributes[:dsid] = dsid end |
#last_modified_in_repository ⇒ Object
returns a datetime in the standard W3C DateTime Format.
ie 2008-10-17T00:17:18.194Z
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/active_fedora/datastream.rb', line 105 def last_modified_in_repository # A hack to get around the fact that you can't call getDatastreamHistory # or API-M getDatasreams on Fedora 3.0 REST API # grabs the CREATED attribute off of the last foxml:datastreamVersion # within the appropriate datastream node in the objectXML if self.pid != nil object_xml = Fedora::FedoraObject.object_xml(self.pid).gsub("\n ","") datastream_xml = REXML::Document.new(object_xml).root.elements["foxml:datastream[@ID='#{self.dsid}']"] if datastream_xml.length > 3 datastream_xml.elements.each do |el| logger.debug el.inspect end end datastream_xml.elements[datastream_xml.length - 2].attributes["CREATED"] else return nil end end |
#pid ⇒ Object
get this datastreams identifier
36 37 38 |
# File 'lib/active_fedora/datastream.rb', line 36 def pid self.attributes[:pid] end |
#pid=(pid) ⇒ Object
set this datastreams parent identifier
41 42 43 |
# File 'lib/active_fedora/datastream.rb', line 41 def pid=(pid) self.attributes[:pid] = pid end |
#save ⇒ Object
Save the datastream into fedora. Also triggers #before_save and #after_save callbacks
77 78 79 80 81 82 |
# File 'lib/active_fedora/datastream.rb', line 77 def save before_save result = Fedora::Repository.instance.save(self) after_save result end |
#size ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/active_fedora/datastream.rb', line 51 def size if !self.attributes.fetch(:dsSize,nil) if self.new_object? self.attributes[:dsSize]=nil else attrs = XmlSimple.xml_in(Fedora::Repository.instance.fetch_custom(self.pid,"datastreams/#{self.dsid}")) self.attributes[:dsSize]=attrs["dsSize"].first end end self.attributes[:dsSize] end |
#to_param ⇒ Object
compatibility method for rails’ url generators. This method will urlescape escape dots, which are apparently invalid characters in a dsid.
66 67 68 |
# File 'lib/active_fedora/datastream.rb', line 66 def to_param dsid.gsub(/\./, '%2e') end |