Class: Valkyrie::Persistence::Fedora::PermissiveSchema

Inherits:
Object
  • Object
show all
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.

Examples:

Passing in a mapping

schema = Valkyrie::Persistence::Fedora::PermissiveSchema.new(member_ids:
  RDF::URI("http://mypredicates.com/member_ids"))
schema.predicate_for(resource: Resource.new, property: :member_ids) # => RDF::URI<"http://mypredicates.com/member_ids">
schema.predicate_for(resource: Resource.new, property: :unknown) # => RDF::URI<"http://example.com/predicate/unknown">

Constant Summary collapse

URI_PREFIX =
'http://example.com/predicate/'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema = {}) ⇒ PermissiveSchema

Returns a new instance of PermissiveSchema.



74
75
76
# File 'lib/valkyrie/persistence/fedora/permissive_schema.rb', line 74

def initialize(schema = {})
  @schema = schema
end

Instance Attribute Details

#schemaObject (readonly)

Returns the value of attribute schema.



73
74
75
# File 'lib/valkyrie/persistence/fedora/permissive_schema.rb', line 73

def schema
  @schema
end

Class Method Details

.alternate_idsObject

Deprecated.

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

.idRDF::URI

Returns:



21
22
23
# File 'lib/valkyrie/persistence/fedora/permissive_schema.rb', line 21

def self.id
  uri_for(:id)
end

.member_idsRDF::URI

Returns:



34
35
36
# File 'lib/valkyrie/persistence/fedora/permissive_schema.rb', line 34

def self.member_ids
  uri_for(:member_ids)
end

.referencesObject

Deprecated.

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

Parameters:

  • property (Symbol)

Returns:



69
70
71
# File 'lib/valkyrie/persistence/fedora/permissive_schema.rb', line 69

def self.uri_for(property)
  RDF::URI("#{URI_PREFIX}#{property}")
end

.valkyrie_boolRDF::URI

Returns:



47
48
49
# File 'lib/valkyrie/persistence/fedora/permissive_schema.rb', line 47

def self.valkyrie_bool
  uri_for(:valkyrie_bool)
end

.valkyrie_datetimeRDF::URI

Returns:



52
53
54
# File 'lib/valkyrie/persistence/fedora/permissive_schema.rb', line 52

def self.valkyrie_datetime
  uri_for(:valkyrie_datetime)
end

.valkyrie_idRDF::URI

Returns:



16
17
18
# File 'lib/valkyrie/persistence/fedora/permissive_schema.rb', line 16

def self.valkyrie_id
  uri_for('valkyrie_id')
end

.valkyrie_intRDF::URI

Returns:



57
58
59
# File 'lib/valkyrie/persistence/fedora/permissive_schema.rb', line 57

def self.valkyrie_int
  uri_for(:valkyrie_int)
end

.valkyrie_timeRDF::URI

Returns:



62
63
64
# File 'lib/valkyrie/persistence/fedora/permissive_schema.rb', line 62

def self.valkyrie_time
  uri_for(:valkyrie_time)
end

Instance Method Details

#predicate_for(resource:, property:) ⇒ Object



78
79
80
# File 'lib/valkyrie/persistence/fedora/permissive_schema.rb', line 78

def predicate_for(resource:, property:)
  schema.fetch(property) { self.class.uri_for(property) }
end

#property_for(resource:, predicate:) ⇒ Object

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'


87
88
89
# File 'lib/valkyrie/persistence/fedora/permissive_schema.rb', line 87

def property_for(resource:, predicate:)
  (schema.find { |_k, v| v == RDF::URI(predicate.to_s) } || []).first || predicate.to_s.gsub(URI_PREFIX, '')
end