Class: ActiveFedora::Datastream
- Inherits:
-
Rubydora::Datastream
- Object
- Rubydora::Datastream
- ActiveFedora::Datastream
- Defined in:
- lib/active_fedora/datastream.rb
Overview
This class represents a Fedora datastream
Direct Known Subclasses
Instance Attribute Summary collapse
-
#digital_object ⇒ Object
writeonly
Sets the attribute digital_object.
-
#fields ⇒ Object
Returns the value of attribute fields.
-
#last_modified ⇒ Object
Returns the value of attribute last_modified.
Class Method Summary collapse
-
.from_xml(tmpl, node) ⇒ Object
Populate a Datastream object based on the “datastream” node from a FOXML file.
Instance Method Summary collapse
- #add_ds_location ⇒ Object
- #add_mime_type ⇒ Object
- #create ⇒ Object
-
#dirty ⇒ Object
Deprecated.
-
#dirty=(value) ⇒ Object
Deprecated.
-
#dirty? ⇒ Boolean
Test whether this datastream been modified since it was last saved Deprecated.
-
#initialize(digital_object, dsid, options = {}) ⇒ Datastream
constructor
A new instance of Datastream.
- #inspect ⇒ Object
- #new_object? ⇒ Boolean
- #profile_from_hash(profile_hash) ⇒ Object
- #save ⇒ Object
-
#serialize! ⇒ Object
serializes any changed data into the content field.
- #size ⇒ Object
-
#solrize_profile ⇒ Object
:nodoc:.
-
#to_param ⇒ Object
compatibility method for rails’ url generators.
- #to_solr(solr_doc = Hash.new) ⇒ Object
- #validate_content_present ⇒ Object
Constructor Details
#initialize(digital_object, dsid, options = {}) ⇒ Datastream
Returns a new instance of Datastream.
10 11 12 13 14 |
# File 'lib/active_fedora/datastream.rb', line 10 def initialize(digital_object, dsid, ={}) ## When you use the versions feature of rubydora (0.5.x), you need to have a 3 argument constructor self.fields={} super end |
Instance Attribute Details
#digital_object=(value) ⇒ Object (writeonly)
Sets the attribute digital_object
6 7 8 |
# File 'lib/active_fedora/datastream.rb', line 6 def digital_object=(value) @digital_object = value 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
.from_xml(tmpl, node) ⇒ Object
Populate a Datastream object based on the “datastream” node from a FOXML file
100 101 102 103 |
# File 'lib/active_fedora/datastream.rb', line 100 def self.from_xml(tmpl, node) tmpl.controlGroup= node['CONTROL_GROUP'] tmpl end |
Instance Method Details
#add_ds_location ⇒ Object
24 25 26 27 |
# File 'lib/active_fedora/datastream.rb', line 24 def add_ds_location if self.controlGroup == 'E' end end |
#add_mime_type ⇒ Object
20 21 22 |
# File 'lib/active_fedora/datastream.rb', line 20 def add_mime_type self.mimeType = 'text/xml' unless self.mimeType end |
#create ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/active_fedora/datastream.rb', line 85 def create run_callbacks :create do repository.add_datastream to_api_params.merge({ :pid => pid, :dsid => dsid }) reset_profile_attributes self end end |
#dirty ⇒ Object
Deprecated
47 48 49 |
# File 'lib/active_fedora/datastream.rb', line 47 def dirty changed? end |
#dirty=(value) ⇒ Object
Deprecated
52 53 54 55 56 57 58 |
# File 'lib/active_fedora/datastream.rb', line 52 def dirty=(value) if value lastModifiedDate_will_change! # an innocent hack to pretend something has changed else changed_attributes.clear end end |
#dirty? ⇒ Boolean
Test whether this datastream been modified since it was last saved Deprecated
42 43 44 |
# File 'lib/active_fedora/datastream.rb', line 42 def dirty? changed? end |
#inspect ⇒ Object
29 30 31 |
# File 'lib/active_fedora/datastream.rb', line 29 def inspect "#<#{self.class}:#{self.hash} @pid=\"#{digital_object ? pid : nil}\" @dsid=\"#{dsid}\" @controlGroup=\"#{controlGroup}\" @dirty=\"#{dirty}\" @mimeType=\"#{mimeType}\" >" end |
#new_object? ⇒ Boolean
60 61 62 |
# File 'lib/active_fedora/datastream.rb', line 60 def new_object? new? end |
#profile_from_hash(profile_hash) ⇒ Object
117 118 119 120 121 |
# File 'lib/active_fedora/datastream.rb', line 117 def profile_from_hash(profile_hash) profile_hash.each_pair do |key,value| profile[key] = value.to_s end end |
#save ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/active_fedora/datastream.rb', line 75 def save run_callbacks :save do return create if new? repository.modify_datastream to_api_params.merge({ :pid => pid, :dsid => dsid }) reset_profile_attributes #Datastream.new(digital_object, dsid) self end end |
#serialize! ⇒ Object
serializes any changed data into the content field
95 96 |
# File 'lib/active_fedora/datastream.rb', line 95 def serialize! end |
#size ⇒ Object
16 17 18 |
# File 'lib/active_fedora/datastream.rb', line 16 def size self.profile['dsSize'] end |
#solrize_profile ⇒ Object
:nodoc:
105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/active_fedora/datastream.rb', line 105 def solrize_profile # :nodoc: profile_hash = {} profile.each_pair do |property,value| if property =~ /Date/ value = Time.parse(value) unless value.is_a?(Time) value = value.xmlschema end profile_hash[property] = value end profile_hash end |
#to_param ⇒ Object
compatibility method for rails’ url generators. This method will urlescape escape dots, which are apparently invalid characters in a dsid.
36 37 38 |
# File 'lib/active_fedora/datastream.rb', line 36 def to_param dsid.gsub(/\./, '%2e') end |
#to_solr(solr_doc = Hash.new) ⇒ Object
123 124 125 |
# File 'lib/active_fedora/datastream.rb', line 123 def to_solr(solr_doc = Hash.new) solr_doc end |
#validate_content_present ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/active_fedora/datastream.rb', line 64 def validate_content_present case controlGroup when 'X','M' @content.present? when 'E','R' dsLocation.present? else raise "Invalid control group: #{controlGroup.inspect}" end end |