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

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

Instance Attribute Summary

Attributes inherited from ValueMapper

#calling_mapper, #value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ValueMapper

for, #initialize, register

Constructor Details

This class inherits a constructor from Valkyrie::ValueMapper

Class Method Details

.handles?(value) ⇒ Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/valkyrie/persistence/fedora/persister/model_converter.rb', line 101

def self.handles?(value)
  value.is_a?(Property) && value.key == :member_ids && Array(value.value).present?
end

Instance Method Details

#apply_first_and_lastObject



115
116
117
118
119
# File 'lib/valkyrie/persistence/fedora/persister/model_converter.rb', line 115

def apply_first_and_last
  return if ordered_list.to_a.empty?
  graph << RDF::Statement.new(value.subject, ::RDF::Vocab::IANA.first, ordered_list.head.next.rdf_subject)
  graph << RDF::Statement.new(value.subject, ::RDF::Vocab::IANA.last, ordered_list.tail.prev.rdf_subject)
end

#graphObject



111
112
113
# File 'lib/valkyrie/persistence/fedora/persister/model_converter.rb', line 111

def graph
  @graph ||= ordered_list.to_graph
end

#initialize_listObject



121
122
123
124
125
# File 'lib/valkyrie/persistence/fedora/persister/model_converter.rb', line 121

def initialize_list
  Array(value.value).each_with_index do |val, index|
    ordered_list.insert_proxy_for_at(index, calling_mapper.for(Property.new(value.subject, :member_id, val, value.adapter, value.resource)).result.value)
  end
end

#ordered_listObject



127
128
129
# File 'lib/valkyrie/persistence/fedora/persister/model_converter.rb', line 127

def ordered_list
  @ordered_list ||= OrderedList.new(RDF::Graph.new, nil, nil, value.adapter)
end

#resultObject



105
106
107
108
109
# File 'lib/valkyrie/persistence/fedora/persister/model_converter.rb', line 105

def result
  initialize_list
  apply_first_and_last
  GraphProperty.new(value.subject, value.key, graph, value.adapter, value.resource)
end