Class: RDF::LDP::InteractionModel
- Inherits:
-
Object
- Object
- RDF::LDP::InteractionModel
- Defined in:
- lib/rdf/ldp/interaction_model.rb
Overview
Provides an interaction model registry.
Constant Summary collapse
- @@interaction_models =
Interaction models are in reverse order of preference for POST/PUT requests; e.g. if a client sends a request with Resource, RDFSource, oand BasicContainer headers, the server gives a basic container.
Interaction models are initialized in the correct order, but with no class registered to handle them.
{ RDF::LDP::RDFSource.to_uri => nil, RDF::LDP::Container.to_uri => nil, RDF::Vocab::LDP.BasicContainer => nil, RDF::LDP::DirectContainer.to_uri => nil, RDF::LDP::IndirectContainer.to_uri => nil, RDF::LDP::NonRDFSource.to_uri => nil }
Class Method Summary collapse
-
.compatible?(uris) ⇒ TrueClass or FalseClass
Test an array of URIs to see if their interaction models are compatible (e.g., all of the URIs refer either to RDF models or non-RDF models, but not a combination of both).
-
.default ⇒ Object
The default registered interaction model.
-
.find(uris) ⇒ Class
Find the appropriate interaction model given a set of Link header URIs.
-
.for(uri) ⇒ Class
Find the interaction model registered for a given uri.
-
.register(klass, opts = {}) ⇒ RDF::LDP::Resource
Register a new interaction model for one or more Link header URIs.
Class Method Details
.compatible?(uris) ⇒ TrueClass or FalseClass
Test an array of URIs to see if their interaction models are compatible (e.g., all of the URIs refer either to RDF models or non-RDF models, but not a combination of both).
87 88 89 90 91 92 93 |
# File 'lib/rdf/ldp/interaction_model.rb', line 87 def compatible?(uris) classes = uris.collect { |m| self.for(m) } (rdf, non_rdf) = classes.compact.partition { |c| c.ancestors.include?(RDFSource) } rdf.empty? || non_rdf.empty? end |
.default ⇒ Object
The default registered interaction model
75 76 77 |
# File 'lib/rdf/ldp/interaction_model.rb', line 75 def default @@default end |
.find(uris) ⇒ Class
Find the appropriate interaction model given a set of Link header URIs.
58 59 60 61 |
# File 'lib/rdf/ldp/interaction_model.rb', line 58 def find(uris) match = @@interaction_models.keys.reverse.find { |u| uris.include? u } self.for(match) || @@default end |
.for(uri) ⇒ Class
Find the interaction model registered for a given uri
69 70 71 |
# File 'lib/rdf/ldp/interaction_model.rb', line 69 def for(uri) @@interaction_models[uri] end |
.register(klass, opts = {}) ⇒ RDF::LDP::Resource
Register a new interaction model for one or more Link header URIs. klass.to_uri will automatically be registered.
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rdf/ldp/interaction_model.rb', line 36 def register(klass, opts = {}) unless klass.ancestors.include?(RDF::LDP::Resource) raise ArgumentError, 'Interaction models must subclass `RDF::LDP::Resource`' end @@default = klass if opts[:default] || @@default.nil? @@interaction_models[klass.to_uri] = klass Array(opts[:for]).each do |model| @@interaction_models[model] = klass end klass end |