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.
35 36 37 38 39 40 41 |
# File 'lib/rdf/ldp/non_rdf_source.rb', line 35 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’.
48 49 50 |
# File 'lib/rdf/ldp/non_rdf_source.rb', line 48 def self.to_uri RDF::Vocab::LDP.NonRDFSource end |
Instance Method Details
#content_type ⇒ StorageAdapter
Returns this resource’s content type.
128 129 130 131 |
# File 'lib/rdf/ldp/non_rdf_source.rb', line 128 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`.
120 121 122 123 124 |
# File 'lib/rdf/ldp/non_rdf_source.rb', line 120 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.
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/rdf/ldp/non_rdf_source.rb', line 69 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.
103 104 105 |
# File 'lib/rdf/ldp/non_rdf_source.rb', line 103 def description RDF::LDP::Resource.find(description_uri, @data) end |
#description_uri ⇒ RDF::URI
Returns uri for this resource’s associated RDFSource.
109 110 111 |
# File 'lib/rdf/ldp/non_rdf_source.rb', line 109 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.
94 95 96 97 |
# File 'lib/rdf/ldp/non_rdf_source.rb', line 94 def destroy super storage.delete end |
#non_rdf_source? ⇒ Boolean
Returns whether this is an ldp:NonRDFSource.
54 55 56 |
# File 'lib/rdf/ldp/non_rdf_source.rb', line 54 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.
138 139 140 |
# File 'lib/rdf/ldp/non_rdf_source.rb', line 138 def to_response exists? && !destroyed? ? storage.io : [] end |
#update(input, c_type) ⇒ Object
82 83 84 85 86 87 |
# File 'lib/rdf/ldp/non_rdf_source.rb', line 82 def update(input, c_type) storage.io { |io| IO.copy_stream(input, io) } super self.content_type = c_type self end |