Class: Valkyrie::Persistence::Fedora::Persister::ModelConverter
- Inherits:
-
Object
- Object
- Valkyrie::Persistence::Fedora::Persister::ModelConverter
- 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, FloatValue, GraphProperty, IdentifiableValue, IntegerValue, InternalValkyrieID, MappedFedoraValue, NestedInternalValkyrieID, NestedProperty, OrderedMembers, OrderedProperties, Property, SymbolValue, TimeValue
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
-
#subject_uri ⇒ Object
readonly
Returns the value of attribute subject_uri.
Instance Method Summary collapse
-
#convert ⇒ Ldp::Container::Basic
Convert a Valkyrie Resource into a RDF LDP basic container.
-
#graph_resource ⇒ Ldp::Container::Basic
Construct the LDP Basic Container modeling the Valkyrie Resource in Fedora.
-
#initialize(resource:, adapter:, subject_uri: RDF::URI("")) ⇒ ModelConverter
constructor
A new instance of ModelConverter.
-
#properties ⇒ Array<Symbol>
Access the Valkyrie attribute names to be used for the Fedora resource properties Filters resource properties to remove properties that should not be persisted to Fedora.
-
#property_converter ⇒ Class
Provide the Class used for values This should be derived from Valkyrie::ValueMapper as a base class.
-
#subject ⇒ RDF::URI
Generate a URI from the Valkyrie Resource ID to be used as the RDF subject for Fedora LDP resources.
Constructor Details
#initialize(resource:, adapter:, subject_uri: RDF::URI("")) ⇒ ModelConverter
Returns a new instance of ModelConverter.
12 13 14 15 16 |
# File 'lib/valkyrie/persistence/fedora/persister/model_converter.rb', line 12 def initialize(resource:, adapter:, subject_uri: RDF::URI("")) @resource = resource @adapter = adapter @subject_uri = subject_uri end |
Instance Attribute Details
#adapter ⇒ Object (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 |
#resource ⇒ Object (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_uri ⇒ Object (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
#convert ⇒ Ldp::Container::Basic
Convert a Valkyrie Resource into a RDF LDP basic container
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/valkyrie/persistence/fedora/persister/model_converter.rb', line 20 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_resource ⇒ Ldp::Container::Basic
Construct the LDP Basic Container modeling the Valkyrie Resource in Fedora
44 45 46 |
# File 'lib/valkyrie/persistence/fedora/persister/model_converter.rb', line 44 def graph_resource @graph_resource ||= ::Ldp::Container::Basic.new(connection, subject, nil, base_path) end |
#properties ⇒ Array<Symbol>
Access the Valkyrie attribute names to be used for the Fedora resource properties Filters resource properties to remove properties that should not be persisted to Fedora.
-
new_record is a virtual property for marking unsaved objects
35 36 37 |
# File 'lib/valkyrie/persistence/fedora/persister/model_converter.rb', line 35 def properties resource_attributes.keys - [:new_record] end |
#property_converter ⇒ Class
Provide the Class used for values This should be derived from Valkyrie::ValueMapper as a base class
57 58 59 |
# File 'lib/valkyrie/persistence/fedora/persister/model_converter.rb', line 57 def property_converter FedoraValue end |
#subject ⇒ RDF::URI
Generate a URI from the Valkyrie Resource ID to be used as the RDF subject for Fedora LDP resources
50 51 52 |
# File 'lib/valkyrie/persistence/fedora/persister/model_converter.rb', line 50 def subject adapter.id_to_uri(resource.id) if resource.try(:id) end |