Class: Valkyrie::Persistence::Fedora::PermissiveSchema
- Inherits:
-
Object
- Object
- Valkyrie::Persistence::Fedora::PermissiveSchema
- Defined in:
- lib/valkyrie/persistence/fedora/permissive_schema.rb
Overview
Default schema for Fedora MetadataAdapter. It’s used to generate a mapping of Resource attributes to predicates. This implementation will make up a URI if one doesn’t exist in a passed in schema.
Constant Summary collapse
- URI_PREFIX =
'http://example.com/predicate/'
Instance Attribute Summary collapse
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Class Method Summary collapse
- .id ⇒ RDF::URI
- .member_ids ⇒ RDF::URI
- .optimistic_lock_token ⇒ RDF::URI
-
.uri_for(property) ⇒ RDF::URI
Cast the property to a URI in the namespace.
- .valkyrie_bool ⇒ RDF::URI
- .valkyrie_datetime ⇒ RDF::URI
- .valkyrie_float ⇒ RDF::URI
- .valkyrie_id ⇒ RDF::URI
- .valkyrie_int ⇒ RDF::URI
- .valkyrie_time ⇒ RDF::URI
Instance Method Summary collapse
-
#initialize(schema = {}) ⇒ PermissiveSchema
constructor
A new instance of PermissiveSchema.
-
#predicate_for(resource:, property:) ⇒ RDF::URI
Find the predicate in the schema for the Valkyrie property If this does not exist, a URI using the property name prefixed by URI_PREFIX generates it.
-
#property_for(resource:, predicate:) ⇒ String
Find the property in the schema.
Constructor Details
#initialize(schema = {}) ⇒ PermissiveSchema
Returns a new instance of PermissiveSchema.
70 71 72 |
# File 'lib/valkyrie/persistence/fedora/permissive_schema.rb', line 70 def initialize(schema = {}) @schema = schema end |
Instance Attribute Details
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
67 68 69 |
# File 'lib/valkyrie/persistence/fedora/permissive_schema.rb', line 67 def schema @schema end |
Class Method Details
.id ⇒ RDF::URI
21 22 23 |
# File 'lib/valkyrie/persistence/fedora/permissive_schema.rb', line 21 def self.id uri_for(:id) end |
.member_ids ⇒ RDF::URI
26 27 28 |
# File 'lib/valkyrie/persistence/fedora/permissive_schema.rb', line 26 def self.member_ids uri_for(:member_ids) end |
.optimistic_lock_token ⇒ RDF::URI
56 57 58 |
# File 'lib/valkyrie/persistence/fedora/permissive_schema.rb', line 56 def self.optimistic_lock_token uri_for(:optimistic_lock_token) end |
.uri_for(property) ⇒ RDF::URI
Cast the property to a URI in the namespace
63 64 65 |
# File 'lib/valkyrie/persistence/fedora/permissive_schema.rb', line 63 def self.uri_for(property) RDF::URI("#{URI_PREFIX}#{property}") end |
.valkyrie_bool ⇒ RDF::URI
31 32 33 |
# File 'lib/valkyrie/persistence/fedora/permissive_schema.rb', line 31 def self.valkyrie_bool uri_for(:valkyrie_bool) end |
.valkyrie_datetime ⇒ RDF::URI
36 37 38 |
# File 'lib/valkyrie/persistence/fedora/permissive_schema.rb', line 36 def self.valkyrie_datetime uri_for(:valkyrie_datetime) end |
.valkyrie_float ⇒ RDF::URI
41 42 43 |
# File 'lib/valkyrie/persistence/fedora/permissive_schema.rb', line 41 def self.valkyrie_float uri_for(:valkyrie_float) end |
.valkyrie_id ⇒ RDF::URI
16 17 18 |
# File 'lib/valkyrie/persistence/fedora/permissive_schema.rb', line 16 def self.valkyrie_id uri_for('valkyrie_id') end |
.valkyrie_int ⇒ RDF::URI
46 47 48 |
# File 'lib/valkyrie/persistence/fedora/permissive_schema.rb', line 46 def self.valkyrie_int uri_for(:valkyrie_int) end |
.valkyrie_time ⇒ RDF::URI
51 52 53 |
# File 'lib/valkyrie/persistence/fedora/permissive_schema.rb', line 51 def self.valkyrie_time uri_for(:valkyrie_time) end |
Instance Method Details
#predicate_for(resource:, property:) ⇒ RDF::URI
Find the predicate in the schema for the Valkyrie property If this does not exist, a URI using the property name prefixed by URI_PREFIX generates it
79 80 81 |
# File 'lib/valkyrie/persistence/fedora/permissive_schema.rb', line 79 def predicate_for(resource:, property:) schema.fetch(property) { self.class.uri_for(property) } end |
#property_for(resource:, predicate:) ⇒ String
Find the property in the schema. If it’s not there check to see if this prediate is in the URI_PREFIX namespace, return the suffix as the property @example:
property_for(resource: nil, predicate: "http://example.com/predicate/internal_resource")
#=> 'internal_resource'
91 92 93 94 95 96 97 |
# File 'lib/valkyrie/persistence/fedora/permissive_schema.rb', line 91 def property_for(resource:, predicate:) existing_predicates = schema.find { |_k, v| v == RDF::URI(predicate.to_s) } predicate_name = predicate.to_s.gsub(URI_PREFIX, '') return predicate_name if existing_predicates.blank? existing_predicates.first end |