Class: ActiveFedora::RDFDatastream
- Extended by:
- Deprecation
- Includes:
- ActiveFedora::RDF::DatastreamIndexing, ActiveTriples::NestedAttributes, ActiveTriples::Properties, ActiveTriples::Reflection
- Defined in:
- lib/active_fedora/rdf/rdf_datastream.rb
Direct Known Subclasses
Constant Summary
Constants included from AttributeMethods
AttributeMethods::AttrNames, AttributeMethods::BLACKLISTED_CLASS_METHODS
Constants included from Callbacks
Class Method Summary collapse
-
.parent_uri(ds) ⇒ Object
Trim the last segment off the URI to get the parents uri.
- .rdf_subject(&block) ⇒ Object
-
.resource_class(klass = nil) ⇒ Class
ActiveTriples::Resource and include ActiveFedora::RDF::Persistence.
Instance Method Summary collapse
- #content ⇒ Object
- #content=(new_content) ⇒ Object
- #content_changed? ⇒ Boolean
- #deprecation_warning ⇒ Object
- #deserialize(data = nil) ⇒ Object
- #empty_or_blank_subject? ⇒ Boolean
- #freeze ⇒ Object
-
#initialize(*args) ⇒ RDFDatastream
constructor
A new instance of RDFDatastream.
- #metadata? ⇒ Boolean
- #parent_uri ⇒ Object
- #refresh_attributes ⇒ Object
-
#resource ⇒ Object
(also: #graph)
The resource is the RdfResource object that stores the graph for the datastream and is the central point for its relationship to other nodes.
- #serialization_format ⇒ Object
- #serialize ⇒ Object
-
#term_values(*values) ⇒ Object
This method allows for delegation.
- #update_indexed_attributes(hash) ⇒ Object
- #uri=(uri) ⇒ Object
Methods included from ActiveFedora::RDF::DatastreamIndexing
Methods inherited from File
#attribute_will_change!, #changed?, #check_fixity, #checksum, #datastream_will_change!, #described_by, #exists!, #inspect, #ldp_connection, #metadata, #metadata_changed?, #new_record?, #refresh, #reload, #remote_content, #serialize!, #to_solr
Methods included from Querying
#default_sort_params, extended
Methods included from Scoping
#initialize_internals_callback, #populate_with_current_scope_attributes
Methods included from Identifiable
Methods included from AttributeMethods
#[], #[]=, #attribute_for_inspect, #attribute_names, #attribute_present?, #attributes, #has_attribute?
Methods included from Callbacks
Methods included from Versionable
#create_version, #has_versions?, #model_type, #restore_version, #versions
Methods included from Persistence
#base_path_for_resource=, #delete, #destroy, #destroy!, #destroyed?, #eradicate, #new_record?, #persisted?, #save, #save!, #update
Methods included from File::Streaming
Methods included from File::Attributes
#assign_attributes, #create_date, #digest, #dirty_size, #empty?, #has_content?, #mime_type, #original_name, #original_name=, #persisted_size, #size
Methods included from Common
#<=>, #==, #frozen?, #ldp_source, #readonly!, #readonly?
Constructor Details
#initialize(*args) ⇒ RDFDatastream
Returns a new instance of RDFDatastream.
10 11 12 13 |
# File 'lib/active_fedora/rdf/rdf_datastream.rb', line 10 def initialize(*args) super deprecation_warning end |
Class Method Details
.parent_uri(ds) ⇒ Object
Trim the last segment off the URI to get the parents uri
27 28 29 30 31 32 33 34 |
# File 'lib/active_fedora/rdf/rdf_datastream.rb', line 27 def parent_uri(ds) m = /^(.*)\/[^\/]*$/.match(ds.uri) if m m[1] else ::RDF::URI.new(nil) end end |
.rdf_subject(&block) ⇒ Object
20 21 22 23 24 |
# File 'lib/active_fedora/rdf/rdf_datastream.rb', line 20 def rdf_subject(&block) return @subject_block = block if block_given? @subject_block ||= ->(ds) { parent_uri(ds) } end |
.resource_class(klass = nil) ⇒ Class
ActiveTriples::Resource and include ActiveFedora::RDF::Persistence.
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/active_fedora/rdf/rdf_datastream.rb', line 41 def resource_class(klass = nil) if klass raise ArgumentError, "#{self} already has a resource_class #{@resource_class}, cannot redefine it to #{klass}" if @resource_class && klass != @resource_class raise ArgumentError, "#{klass} must be a subclass of ActiveTriples::Resource" unless klass < ActiveTriples::Resource end @resource_class ||= begin klass = Class.new(klass || ActiveTriples::Resource) klass.send(:include, RDF::Persistence) klass end end |
Instance Method Details
#content ⇒ Object
70 71 72 |
# File 'lib/active_fedora/rdf/rdf_datastream.rb', line 70 def content serialize end |
#content=(new_content) ⇒ Object
74 75 76 77 78 |
# File 'lib/active_fedora/rdf/rdf_datastream.rb', line 74 def content=(new_content) resource.clear! resource << deserialize(new_content) content end |
#content_changed? ⇒ Boolean
85 86 87 88 89 90 |
# File 'lib/active_fedora/rdf/rdf_datastream.rb', line 85 def content_changed? return false unless instance_variable_defined? :@resource return true if empty_or_blank_subject? # can't be serialized because a subject hasn't been assigned yet. @content = serialize super end |
#deprecation_warning ⇒ Object
15 16 17 |
# File 'lib/active_fedora/rdf/rdf_datastream.rb', line 15 def deprecation_warning Deprecation.warn(RDFDatastream, "RDFDatastream is deprecated and will be removed in ActiveFedora 11", caller(2)) end |
#deserialize(data = nil) ⇒ Object
152 153 154 155 156 157 158 159 160 161 |
# File 'lib/active_fedora/rdf/rdf_datastream.rb', line 152 def deserialize(data = nil) return ::RDF::Graph.new if new_record? && data.nil? data ||= remote_content # Because datastream_content can return nil, we should check that here. return ::RDF::Graph.new if data.nil? data.force_encoding('utf-8') ::RDF::Graph.new << ::RDF::Reader.for(serialization_format).new(data) end |
#empty_or_blank_subject? ⇒ Boolean
92 93 94 |
# File 'lib/active_fedora/rdf/rdf_datastream.rb', line 92 def empty_or_blank_subject? resource.rdf_subject.node? || resource.rdf_subject.value.blank? end |
#freeze ⇒ Object
96 97 98 |
# File 'lib/active_fedora/rdf/rdf_datastream.rb', line 96 def freeze @resource.freeze end |
#metadata? ⇒ Boolean
66 67 68 |
# File 'lib/active_fedora/rdf/rdf_datastream.rb', line 66 def true end |
#parent_uri ⇒ Object
62 63 64 |
# File 'lib/active_fedora/rdf/rdf_datastream.rb', line 62 def parent_uri self.class.parent_uri(self) end |
#refresh_attributes ⇒ Object
126 127 128 |
# File 'lib/active_fedora/rdf/rdf_datastream.rb', line 126 def refresh_attributes @resource = nil end |
#resource ⇒ Object Also known as: graph
The resource is the RdfResource object that stores the graph for the datastream and is the central point for its relationship to other nodes.
set_value, get_value, and property accessors are delegated to this object.
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/active_fedora/rdf/rdf_datastream.rb', line 106 def resource @resource ||= begin klass = self.class.resource_class klass.properties.merge(self.class.properties).each do |_prop, config| klass.property(config.term, predicate: config.predicate, class_name: config.class_name) end klass.accepts_nested_attributes_for(*.keys) unless .blank? uri_stub = self.class.rdf_subject.call(self) r = klass.new(uri_stub) r.datastream = self r << deserialize r end end |
#serialization_format ⇒ Object
163 164 165 |
# File 'lib/active_fedora/rdf/rdf_datastream.rb', line 163 def serialization_format raise "you must override the `serialization_format' method in a subclass" end |
#serialize ⇒ Object
147 148 149 150 |
# File 'lib/active_fedora/rdf/rdf_datastream.rb', line 147 def serialize resource.set_subject!(parent_uri) if parent_uri && rdf_subject.node? resource.dump serialization_format end |
#term_values(*values) ⇒ Object
This method allows for delegation. This patches the fact that there’s no consistent API for allowing delegation - we’re matching the OmDatastream implementation as our “consistency” point. @TODO: We may need to enable deep RDF delegation at one point.
135 136 137 |
# File 'lib/active_fedora/rdf/rdf_datastream.rb', line 135 def term_values(*values) send(values.first) end |
#update_indexed_attributes(hash) ⇒ Object
139 140 141 142 143 144 145 |
# File 'lib/active_fedora/rdf/rdf_datastream.rb', line 139 def update_indexed_attributes(hash) hash.each do |fields, value| fields.each do |field| send("#{field}=", value) end end end |
#uri=(uri) ⇒ Object
80 81 82 83 |
# File 'lib/active_fedora/rdf/rdf_datastream.rb', line 80 def uri=(uri) super resource.set_subject!(parent_uri) if empty_or_blank_subject? end |