Class: Valkyrie::Persistence::Fedora::MetadataAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/valkyrie/persistence/fedora/metadata_adapter.rb

Overview

Metadata Adapter for Fedora adapter.

Examples:

Instantiate with connection to Fedora.

Valkyrie::Persistence::Fedora::MetadataAdapter.new(
  connection: ::Ldp::Client.new("http://localhost:8988/rest"),
  base_path: "test_fed",
  schema: Valkyrie::Persistence::Fedora::PermissiveSchema.new(title: RDF::URI("http://bad.com/title"))
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection:, base_path: "/", schema: Valkyrie::Persistence::Fedora::PermissiveSchema.new) ⇒ MetadataAdapter

Returns a new instance of MetadataAdapter.



13
14
15
16
17
# File 'lib/valkyrie/persistence/fedora/metadata_adapter.rb', line 13

def initialize(connection:, base_path: "/", schema: Valkyrie::Persistence::Fedora::PermissiveSchema.new)
  @connection = connection
  @base_path = base_path
  @schema = schema
end

Instance Attribute Details

#base_pathObject (readonly)

Returns the value of attribute base_path.



12
13
14
# File 'lib/valkyrie/persistence/fedora/metadata_adapter.rb', line 12

def base_path
  @base_path
end

#connectionObject (readonly)

Returns the value of attribute connection.



12
13
14
# File 'lib/valkyrie/persistence/fedora/metadata_adapter.rb', line 12

def connection
  @connection
end

#schemaObject (readonly)

Returns the value of attribute schema.



12
13
14
# File 'lib/valkyrie/persistence/fedora/metadata_adapter.rb', line 12

def schema
  @schema
end

Instance Method Details

#connection_prefixObject



43
44
45
# File 'lib/valkyrie/persistence/fedora/metadata_adapter.rb', line 43

def connection_prefix
  "#{connection.http.url_prefix}/#{base_path}"
end

#id_to_uri(id) ⇒ Object



35
36
37
# File 'lib/valkyrie/persistence/fedora/metadata_adapter.rb', line 35

def id_to_uri(id)
  RDF::URI("#{connection_prefix}/#{pair_path(id)}/#{CGI.escape(id.to_s)}")
end

#pair_path(id) ⇒ Object



39
40
41
# File 'lib/valkyrie/persistence/fedora/metadata_adapter.rb', line 39

def pair_path(id)
  id.to_s.split(/[-\/]/).first.split("").each_slice(2).map(&:join).join("/")
end

#persisterObject



23
24
25
# File 'lib/valkyrie/persistence/fedora/metadata_adapter.rb', line 23

def persister
  Valkyrie::Persistence::Fedora::Persister.new(adapter: self)
end

#query_serviceObject



19
20
21
# File 'lib/valkyrie/persistence/fedora/metadata_adapter.rb', line 19

def query_service
  @query_service ||= Valkyrie::Persistence::Fedora::QueryService.new(adapter: self)
end

#resource_factoryObject



27
28
29
# File 'lib/valkyrie/persistence/fedora/metadata_adapter.rb', line 27

def resource_factory
  Valkyrie::Persistence::Fedora::Persister::ResourceFactory.new(adapter: self)
end

#uri_to_id(uri) ⇒ Object



31
32
33
# File 'lib/valkyrie/persistence/fedora/metadata_adapter.rb', line 31

def uri_to_id(uri)
  Valkyrie::ID.new(CGI.unescape(uri.to_s.gsub(/^.*\//, '')))
end