Class: RDF::LDP::NonRDFSource
- Defined in:
- lib/rdf/ldp/non_rdf_source.rb,
lib/rdf/ldp/storage_adapters/file_storage_adapter.rb
Overview
A NonRDFSource describes a ‘Resource` whose response body is a format other than an RDF serialization. The persistent state of the resource, as represented by the body, is persisted to an IO stream provided by a `RDF::LDP::NonRDFSource::StorageAdapter` given by `#storage`.
In addition to the properties stored by the ‘RDF::LDP::Resource#metagraph`, `NonRDFSource`s also store a content type (format).
When a ‘NonRDFSource` is created, it also creates an `RDFSource` which describes it. This resource is created at the URI in `#description_uri`, the resource itself is returned by `#description`.
Defined Under Namespace
Classes: FileStorageAdapter
Constant Summary collapse
- DEFAULT_ADAPTER =
Use the default filesystem-based storage adapter
RDF::LDP::NonRDFSource::FileStorageAdapter
- FORMAT_TERM =
Use DC elements format
RDF::Vocab::DC11.format.freeze
Constants inherited from Resource
Resource::CONTAINS_URI, Resource::INVALIDATED_AT_URI, Resource::MODIFIED_URI
Instance Attribute Summary collapse
-
#storage ⇒ Object
readonly
Returns the value of attribute storage.
Attributes inherited from Resource
Class Method Summary collapse
-
.to_uri ⇒ RDF::URI
Uri with lexical representation ‘www.w3.org/ns/ldp#NonRDFSource’.
Instance Method Summary collapse
-
#content_type ⇒ StorageAdapter
This resource’s content type.
-
#content_type=(content_type) ⇒ StorageAdapter
Sets the MIME type for the resource in ‘metagraph`.
-
#create(input, c_type) ⇒ RDF::LDP::NonRDFSource
Self.
-
#description ⇒ RDF::LDP::RDFSource
Resource describing this resource.
-
#description_uri ⇒ RDF::URI
Uri for this resource’s associated RDFSource.
-
#destroy ⇒ Object
Deletes the LDP-NR contents from the storage medium and marks the resource as destroyed.
-
#initialize(subject_uri, data = RDF::Repository.new, storage_adapter = DEFAULT_ADAPTER) ⇒ NonRDFSource
constructor
A new instance of NonRDFSource.
-
#non_rdf_source? ⇒ Boolean
Whether this is an ldp:NonRDFSource.
-
#to_response ⇒ #each
The response body.
- #update(input, c_type) ⇒ Object
Methods inherited from Resource
#allowed_methods, #container?, #containers, #destroyed?, #etag, #exists?, find, gen_id, interaction_model, #last_modified, #ldp_resource?, #match?, metagraph_name, #rdf_source?, #request, #to_uri
Constructor Details
#initialize(subject_uri, data = RDF::Repository.new, storage_adapter = DEFAULT_ADAPTER) ⇒ NonRDFSource
Returns a new instance of NonRDFSource.
33 34 35 36 37 38 39 |
# File 'lib/rdf/ldp/non_rdf_source.rb', line 33 def initialize(subject_uri, data = RDF::Repository.new, storage_adapter = DEFAULT_ADAPTER) data ||= RDF::Repository.new # allows explict `nil` pass @storage = storage_adapter.new(self) super(subject_uri, data) end |
Instance Attribute Details
#storage ⇒ Object (readonly)
Returns the value of attribute storage.
21 22 23 |
# File 'lib/rdf/ldp/non_rdf_source.rb', line 21 def storage @storage end |
Class Method Details
.to_uri ⇒ RDF::URI
Returns uri with lexical representation ‘www.w3.org/ns/ldp#NonRDFSource’.
46 47 48 |
# File 'lib/rdf/ldp/non_rdf_source.rb', line 46 def self.to_uri RDF::Vocab::LDP.NonRDFSource end |
Instance Method Details
#content_type ⇒ StorageAdapter
Returns this resource’s content type.
126 127 128 129 |
# File 'lib/rdf/ldp/non_rdf_source.rb', line 126 def content_type format_triple = .first([subject_uri, FORMAT_TERM, :format]) format_triple.nil? ? nil : format_triple.object.object end |
#content_type=(content_type) ⇒ StorageAdapter
Sets the MIME type for the resource in ‘metagraph`.
118 119 120 121 122 |
# File 'lib/rdf/ldp/non_rdf_source.rb', line 118 def content_type=(content_type) .delete([subject_uri, FORMAT_TERM]) << RDF::Statement(subject_uri, FORMAT_TERM, content_type) end |
#create(input, c_type) ⇒ RDF::LDP::NonRDFSource
Returns self.
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/rdf/ldp/non_rdf_source.rb', line 67 def create(input, c_type) storage.io { |io| IO.copy_stream(input, io) } super self.content_type = c_type RDFSource.new(description_uri, @data) .create(StringIO.new, 'application/n-triples') self end |
#description ⇒ RDF::LDP::RDFSource
Returns resource describing this resource.
101 102 103 |
# File 'lib/rdf/ldp/non_rdf_source.rb', line 101 def description RDF::LDP::Resource.find(description_uri, @data) end |
#description_uri ⇒ RDF::URI
Returns uri for this resource’s associated RDFSource.
107 108 109 |
# File 'lib/rdf/ldp/non_rdf_source.rb', line 107 def description_uri subject_uri / '.well-known' / 'desc' end |
#destroy ⇒ Object
Deletes the LDP-NR contents from the storage medium and marks the resource as destroyed.
92 93 94 95 |
# File 'lib/rdf/ldp/non_rdf_source.rb', line 92 def destroy super storage.delete end |
#non_rdf_source? ⇒ Boolean
Returns whether this is an ldp:NonRDFSource.
52 53 54 |
# File 'lib/rdf/ldp/non_rdf_source.rb', line 52 def non_rdf_source? true end |
#to_response ⇒ #each
Returns the response body. This is normally the StorageAdapter’s IO object in read and binary mode.
136 137 138 |
# File 'lib/rdf/ldp/non_rdf_source.rb', line 136 def to_response exists? && !destroyed? ? storage.io : [] end |
#update(input, c_type) ⇒ Object
80 81 82 83 84 85 |
# File 'lib/rdf/ldp/non_rdf_source.rb', line 80 def update(input, c_type) storage.io { |io| IO.copy_stream(input, io) } super self.content_type = c_type self end |