Class: Valkyrie::Persistence::Fedora::Persister::ModelConverter

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

Overview

Responsible for converting Resource to LDP::Container::Basic

Defined Under Namespace

Classes: BooleanValue, CompositeProperty, DateTimeValue, EnumerableValue, FedoraValue, GraphProperty, IdentifiableValue, IntegerValue, InternalValkyrieID, MappedFedoraValue, NestedInternalValkyrieID, NestedProperty, OrderedMembers, Property, TimeValue

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource:, adapter:, subject_uri: RDF::URI("")) ⇒ ModelConverter

Returns a new instance of ModelConverter.



8
9
10
11
12
# File 'lib/valkyrie/persistence/fedora/persister/model_converter.rb', line 8

def initialize(resource:, adapter:, subject_uri: RDF::URI(""))
  @resource = resource
  @adapter = adapter
  @subject_uri = subject_uri
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



6
7
8
# File 'lib/valkyrie/persistence/fedora/persister/model_converter.rb', line 6

def adapter
  @adapter
end

#resourceObject (readonly)

Returns the value of attribute resource.



6
7
8
# File 'lib/valkyrie/persistence/fedora/persister/model_converter.rb', line 6

def resource
  @resource
end

#subject_uriObject (readonly)

Returns the value of attribute subject_uri.



6
7
8
# File 'lib/valkyrie/persistence/fedora/persister/model_converter.rb', line 6

def subject_uri
  @subject_uri
end

Instance Method Details

#convertObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/valkyrie/persistence/fedora/persister/model_converter.rb', line 14

def convert
  graph_resource.graph.delete([nil, nil, nil])
  properties.each do |property|
    values = resource_attributes[property]

    output = property_converter.for(Property.new(subject_uri, property, values, adapter, resource)).result
    graph_resource.graph << output.to_graph
  end
  graph_resource
end

#graph_resourceObject



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

def graph_resource
  @graph_resource ||= ::Ldp::Container::Basic.new(connection, subject, nil, base_path)
end

#propertiesObject



25
26
27
# File 'lib/valkyrie/persistence/fedora/persister/model_converter.rb', line 25

def properties
  resource_attributes.keys - [:new_record]
end

#property_converterObject



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

def property_converter
  FedoraValue
end

#subjectObject



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

def subject
  adapter.id_to_uri(resource.id) if resource.try(:id)
end