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::Datastream
Attributes inherited from Fedora::BaseObject
#attributes, #blob, #errors, #new_object, #uri
Class Method Summary collapse
Instance Method Summary collapse
- #after_save ⇒ Object
-
#before_save ⇒ Object
:nodoc:.
-
#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
has 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
saves this datastream into fedora.
-
#to_param ⇒ Object
compatibility method for rails’ url generators.
Methods inherited from Fedora::Datastream
#control_group, #control_group=, #dsid, #label, #label=, #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
26 27 28 |
# File 'lib/active_fedora/datastream.rb', line 26 def self.delete(parent_pid, dsid) Fedora::Repository.instance.delete("%s/datastreams/%s"%[parent_pid, dsid]) end |
.from_xml(tmpl, node) ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/active_fedora/datastream.rb', line 76 def self.from_xml(tmpl, node) node.xpath("foxml:xmlContent/fields").each do |f| # tmpl.send("#{f.name}_append", f.content) end tmpl.instance_variable_set(:@dirty, false) tmpl.control_group= node['CONTROL_GROUP'] tmpl end |
Instance Method Details
#after_save ⇒ Object
85 86 87 |
# File 'lib/active_fedora/datastream.rb', line 85 def after_save self.dirty = false end |
#before_save ⇒ Object
:nodoc:
70 71 72 |
# File 'lib/active_fedora/datastream.rb', line 70 def before_save # :nodoc: #check_concurrency end |
#check_concurrency ⇒ Object
:nodoc:
112 113 114 |
# File 'lib/active_fedora/datastream.rb', line 112 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 |
# File 'lib/active_fedora/datastream.rb', line 22 def content=(content) self.blob = content end |
#delete ⇒ Object
30 31 32 |
# File 'lib/active_fedora/datastream.rb', line 30 def delete self.class.delete(self.pid, self.dsid) end |
#dirty? ⇒ Boolean
has this datastream been modified since it was last saved?
58 59 60 |
# File 'lib/active_fedora/datastream.rb', line 58 def dirty? @dirty end |
#dsid=(dsid) ⇒ Object
set this datastreams identifier (note: sets both dsID and dsid)
45 46 47 48 |
# File 'lib/active_fedora/datastream.rb', line 45 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
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/active_fedora/datastream.rb', line 91 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
35 36 37 |
# File 'lib/active_fedora/datastream.rb', line 35 def pid self.attributes[:pid] end |
#pid=(pid) ⇒ Object
set this datastreams parent identifier
40 41 42 |
# File 'lib/active_fedora/datastream.rb', line 40 def pid=(pid) self.attributes[:pid] = pid end |
#save ⇒ Object
saves this datastream into fedora.
63 64 65 66 67 68 |
# File 'lib/active_fedora/datastream.rb', line 63 def save before_save result = Fedora::Repository.instance.save(self) after_save result end |
#to_param ⇒ Object
compatibility method for rails’ url generators. This method will urlescape escape dots, which are apparently invalid characters in a dsid.
53 54 55 |
# File 'lib/active_fedora/datastream.rb', line 53 def to_param dsid.gsub(/\./, '%2e') end |