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
-
.alternate_ids ⇒ Object
deprecated
Deprecated.
Please use PermissiveSchema.uri_for instead
- .id ⇒ RDF::URI
- .member_ids ⇒ RDF::URI
- .optimistic_lock_token ⇒ RDF::URI
-
.references ⇒ Object
deprecated
Deprecated.
Please use PermissiveSchema.uri_for instead
-
.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.
86 87 88 |
# File 'lib/valkyrie/persistence/fedora/permissive_schema.rb', line 86 def initialize(schema = {}) @schema = schema end |
Instance Attribute Details
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
83 84 85 |
# File 'lib/valkyrie/persistence/fedora/permissive_schema.rb', line 83 def schema @schema end |
Class Method Details
.alternate_ids ⇒ Object
Please use uri_for instead
26 27 28 29 30 31 |
# File 'lib/valkyrie/persistence/fedora/permissive_schema.rb', line 26 def self.alternate_ids warn "[DEPRECATION] `alternate_ids` is deprecated and will be removed in the next major release. " \ "It was never used internally - please use `uri_for(:alternate_ids)` " \ "Called from #{Gem.location_of_caller.join(':')}" uri_for(:alternate_ids) end |
.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
34 35 36 |
# File 'lib/valkyrie/persistence/fedora/permissive_schema.rb', line 34 def self.member_ids uri_for(:member_ids) end |
.optimistic_lock_token ⇒ RDF::URI
72 73 74 |
# File 'lib/valkyrie/persistence/fedora/permissive_schema.rb', line 72 def self.optimistic_lock_token uri_for(:optimistic_lock_token) end |
.references ⇒ Object
Please use uri_for instead
39 40 41 42 43 44 |
# File 'lib/valkyrie/persistence/fedora/permissive_schema.rb', line 39 def self.references warn "[DEPRECATION] `references` is deprecated and will be removed in the next major release. " \ "It was never used internally - please use `uri_for(:references)` " \ "Called from #{Gem.location_of_caller.join(':')}" uri_for(:references) end |
.uri_for(property) ⇒ RDF::URI
Cast the property to a URI in the namespace
79 80 81 |
# File 'lib/valkyrie/persistence/fedora/permissive_schema.rb', line 79 def self.uri_for(property) RDF::URI("#{URI_PREFIX}#{property}") end |
.valkyrie_bool ⇒ RDF::URI
47 48 49 |
# File 'lib/valkyrie/persistence/fedora/permissive_schema.rb', line 47 def self.valkyrie_bool uri_for(:valkyrie_bool) end |
.valkyrie_datetime ⇒ RDF::URI
52 53 54 |
# File 'lib/valkyrie/persistence/fedora/permissive_schema.rb', line 52 def self.valkyrie_datetime uri_for(:valkyrie_datetime) end |
.valkyrie_float ⇒ RDF::URI
57 58 59 |
# File 'lib/valkyrie/persistence/fedora/permissive_schema.rb', line 57 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
62 63 64 |
# File 'lib/valkyrie/persistence/fedora/permissive_schema.rb', line 62 def self.valkyrie_int uri_for(:valkyrie_int) end |
.valkyrie_time ⇒ RDF::URI
67 68 69 |
# File 'lib/valkyrie/persistence/fedora/permissive_schema.rb', line 67 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
95 96 97 |
# File 'lib/valkyrie/persistence/fedora/permissive_schema.rb', line 95 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'
107 108 109 110 111 112 113 |
# File 'lib/valkyrie/persistence/fedora/permissive_schema.rb', line 107 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.nil? || existing_predicates.empty? existing_predicates.first end |