Class: ActiveFedora::RDFDatastream
- Inherits:
-
Datastream
- Object
- Rubydora::Datastream
- Datastream
- ActiveFedora::RDFDatastream
- Includes:
- RdfNode, Solrizer::Common
- Defined in:
- lib/active_fedora/rdf_datastream.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Datastream
#digital_object, #last_modified
Class Method Summary collapse
-
.rdf_subject {|ds| ... } ⇒ Object
Register a ruby block that evaluates to the subject of the graph By default, the block returns the current object’s pid This should override the method in RdfObject, which just creates a b-node by default.
Instance Method Summary collapse
-
#content ⇒ Object
Overriding so that one can call ds.content on an unsaved datastream and they will see the serialized format.
- #content=(content) ⇒ Object
- #content_changed? ⇒ Boolean
-
#deserialize(data = nil) ⇒ Object
Populate a RDFDatastream object based on the “datastream” content Assumes that the datastream contains RDF content.
- #graph ⇒ Object
- #metadata? ⇒ Boolean
- #prefix(name) ⇒ Object
- #serialization_format ⇒ Object
-
#serialize ⇒ Object
Creates a RDF datastream for insertion into a Fedora Object Note: This method is implemented on SemanticNode instead of RelsExtDatastream because SemanticNode contains the relationships array.
-
#to_solr(solr_doc = Hash.new) ⇒ Object
:nodoc:.
Methods included from RdfNode
#==, #append, #attributes=, #config_for_term_or_uri, #delete_predicate, #destroy, #find_predicate, #get_values, #insert_child, #mark_for_destruction, #marked_for_destruction?, #new_record=, #new_record?, #query, rdf_registry, #rdf_subject, #reset_child_cache!, #reset_rdf_subject!, #set_value, #target_class
Methods inherited from Datastream
#create, #initialize, #inspect, #label, #profile_from_hash, #realLabel, #save, #serialize!, #solrize_profile, #to_param, #validate_content_present
Constructor Details
This class inherits a constructor from ActiveFedora::Datastream
Class Method Details
.rdf_subject {|ds| ... } ⇒ Object
Register a ruby block that evaluates to the subject of the graph By default, the block returns the current object’s pid This should override the method in RdfObject, which just creates a b-node by default
20 21 22 23 24 25 26 |
# File 'lib/active_fedora/rdf_datastream.rb', line 20 def rdf_subject &block if block_given? return @subject_block = block end @subject_block ||= lambda { |ds| RDF::URI.new("info:fedora/#{ds.pid}") } end |
Instance Method Details
#content ⇒ Object
Overriding so that one can call ds.content on an unsaved datastream and they will see the serialized format
40 41 42 |
# File 'lib/active_fedora/rdf_datastream.rb', line 40 def content serialize end |
#content=(content) ⇒ Object
44 45 46 47 |
# File 'lib/active_fedora/rdf_datastream.rb', line 44 def content=(content) reset_child_cache! @graph = deserialize(content) end |
#content_changed? ⇒ Boolean
49 50 51 52 53 54 |
# File 'lib/active_fedora/rdf_datastream.rb', line 49 def content_changed? # we haven't touched the graph, so it isn't changed (avoid a force load) return false unless instance_variable_defined? :@graph @content = serialize super end |
#deserialize(data = nil) ⇒ Object
Populate a RDFDatastream object based on the “datastream” content Assumes that the datastream contains RDF content
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/active_fedora/rdf_datastream.rb', line 73 def deserialize(data = nil) repository = RDF::Repository.new return repository if new? and data.nil? data ||= datastream_content data.force_encoding('utf-8') RDF::Reader.for(serialization_format).new(data) do |reader| reader.each_statement do |statement| repository << statement end end repository end |
#graph ⇒ Object
88 89 90 91 92 |
# File 'lib/active_fedora/rdf_datastream.rb', line 88 def graph @graph ||= begin deserialize end end |
#metadata? ⇒ Boolean
29 30 31 |
# File 'lib/active_fedora/rdf_datastream.rb', line 29 def true end |
#prefix(name) ⇒ Object
33 34 35 36 37 |
# File 'lib/active_fedora/rdf_datastream.rb', line 33 def prefix(name) name = name.to_s unless name.is_a? String pre = dsid.underscore return "#{pre}__#{name}".to_sym end |
#serialization_format ⇒ Object
94 95 96 |
# File 'lib/active_fedora/rdf_datastream.rb', line 94 def serialization_format raise "you must override the `serialization_format' method in a subclass" end |
#serialize ⇒ Object
Creates a RDF datastream for insertion into a Fedora Object Note: This method is implemented on SemanticNode instead of RelsExtDatastream because SemanticNode contains the relationships array
100 101 102 103 104 |
# File 'lib/active_fedora/rdf_datastream.rb', line 100 def serialize update_subjects_to_use_a_real_pid! RDF::Writer.for(serialization_format).dump(graph) end |
#to_solr(solr_doc = Hash.new) ⇒ Object
:nodoc:
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/active_fedora/rdf_datastream.rb', line 56 def to_solr(solr_doc = Hash.new) # :nodoc: fields.each do |field_key, field_info| values = get_values(rdf_subject, field_key) if values Array(values).each do |val| val = val.to_s if val.kind_of? RDF::URI self.class.create_and_insert_terms(prefix(field_key), val, field_info[:behaviors], solr_doc) end end end solr_doc end |