active-fedora 9.10.0 → 9.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -0
  3. data/History.txt +3 -0
  4. data/active-fedora.gemspec +3 -2
  5. data/lib/active_fedora/aggregation/base_extension.rb +17 -0
  6. data/lib/active_fedora/aggregation/list_source.rb +103 -0
  7. data/lib/active_fedora/aggregation/ordered_reader.rb +27 -0
  8. data/lib/active_fedora/aggregation/proxy.rb +18 -0
  9. data/lib/active_fedora/aggregation.rb +11 -0
  10. data/lib/active_fedora/associations/builder/aggregation.rb +51 -0
  11. data/lib/active_fedora/associations/builder/filter.rb +18 -0
  12. data/lib/active_fedora/associations/builder/orders.rb +63 -0
  13. data/lib/active_fedora/associations/filter_association.rb +71 -0
  14. data/lib/active_fedora/associations/orders_association.rb +149 -0
  15. data/lib/active_fedora/associations.rb +40 -0
  16. data/lib/active_fedora/attached_files.rb +2 -1
  17. data/lib/active_fedora/attribute_methods.rb +4 -4
  18. data/lib/active_fedora/autosave_association.rb +14 -0
  19. data/lib/active_fedora/base.rb +1 -0
  20. data/lib/active_fedora/cleaner.rb +1 -1
  21. data/lib/active_fedora/errors.rb +3 -0
  22. data/lib/active_fedora/fedora.rb +17 -7
  23. data/lib/active_fedora/file/attributes.rb +6 -6
  24. data/lib/active_fedora/file/streaming.rb +13 -4
  25. data/lib/active_fedora/file.rb +1 -16
  26. data/lib/active_fedora/orders/collection_proxy.rb +8 -0
  27. data/lib/active_fedora/orders/list_node.rb +161 -0
  28. data/lib/active_fedora/orders/ordered_list.rb +264 -0
  29. data/lib/active_fedora/orders/target_proxy.rb +60 -0
  30. data/lib/active_fedora/orders.rb +12 -0
  31. data/lib/active_fedora/reflection.rb +216 -43
  32. data/lib/active_fedora/relation/finder_methods.rb +2 -2
  33. data/lib/active_fedora/validations.rb +1 -1
  34. data/lib/active_fedora/version.rb +1 -1
  35. data/lib/active_fedora/with_metadata/metadata_node.rb +1 -2
  36. data/lib/active_fedora.rb +7 -0
  37. data/lib/generators/active_fedora/config/solr/templates/solr/config/schema.xml +1 -1
  38. data/solr/config/schema.xml +1 -1
  39. data/spec/integration/attached_files_spec.rb +4 -4
  40. data/spec/integration/attributes_spec.rb +8 -0
  41. data/spec/integration/file_spec.rb +23 -1
  42. data/spec/integration/has_many_associations_spec.rb +23 -0
  43. data/spec/integration/om_datastream_spec.rb +6 -6
  44. data/spec/integration/versionable_spec.rb +6 -6
  45. data/spec/unit/active_fedora_spec.rb +1 -1
  46. data/spec/unit/aggregation/list_source_spec.rb +134 -0
  47. data/spec/unit/aggregation/ordered_reader_spec.rb +43 -0
  48. data/spec/unit/fedora_spec.rb +1 -1
  49. data/spec/unit/file_spec.rb +0 -19
  50. data/spec/unit/filter_spec.rb +133 -0
  51. data/spec/unit/ordered_spec.rb +369 -0
  52. data/spec/unit/orders/list_node_spec.rb +151 -0
  53. data/spec/unit/orders/ordered_list_spec.rb +335 -0
  54. data/spec/unit/orders/reflection_spec.rb +22 -0
  55. data/spec/unit/reflection_spec.rb +2 -4
  56. metadata +29 -7
@@ -31,23 +31,23 @@ module ActiveFedora
31
31
  super
32
32
  end
33
33
 
34
- # Raises an ActiveRecord::DangerousAttributeError exception when an
34
+ # Raises an ActiveFedora::DangerousAttributeError exception when an
35
35
  # \Active \Record method is defined in the model, otherwise +false+.
36
36
  #
37
37
  # class Person < ActiveRecord::Base
38
38
  # def save
39
- # 'already defined by Active Record'
39
+ # 'already defined by Active Fedora'
40
40
  # end
41
41
  # end
42
42
  #
43
43
  # Person.instance_method_already_implemented?(:save)
44
- # # => ActiveRecord::DangerousAttributeError: save is defined by Active Record. Check to make sure that you don't have an attribute or method with the same name.
44
+ # # => ActiveFedora::DangerousAttributeError: save is defined by Active Record. Check to make sure that you don't have an attribute or method with the same name.
45
45
  #
46
46
  # Person.instance_method_already_implemented?(:name)
47
47
  # # => false
48
48
  def instance_method_already_implemented?(method_name)
49
49
  if dangerous_attribute_method?(method_name)
50
- raise DangerousAttributeError, "#{method_name} is defined by Active Record. Check to make sure that you don't have an attribute or method with the same name."
50
+ raise DangerousAttributeError, "#{method_name} is defined by Active Fedora. Check to make sure that you don't have an attribute or method with the same name."
51
51
  end
52
52
 
53
53
  if superclass == Base
@@ -153,6 +153,7 @@ module ActiveFedora
153
153
  # Reloads the attributes of the object as usual and clears <tt>marked_for_destruction</tt> flag.
154
154
  def reload
155
155
  @marked_for_destruction = false
156
+ @destroyed_by_association = nil
156
157
  super
157
158
  end
158
159
 
@@ -172,6 +173,19 @@ module ActiveFedora
172
173
  @marked_for_destruction
173
174
  end
174
175
 
176
+ # Records the association that is being destroyed and destroying this
177
+ # record in the process.
178
+ def destroyed_by_association=(reflection)
179
+ @destroyed_by_association = reflection
180
+ end
181
+
182
+ # Returns the association for the parent being destroyed.
183
+ #
184
+ # Used to avoid updating the counter cache unnecessarily.
185
+ def destroyed_by_association
186
+ @destroyed_by_association
187
+ end
188
+
175
189
  # Returns whether or not this record has been changed in any way (including whether
176
190
  # any of its nested autosave associations are likewise changed)
177
191
  def changed_for_autosave?
@@ -51,6 +51,7 @@ module ActiveFedora
51
51
  include LoadableFromJson
52
52
  include Schema
53
53
  include Pathing
54
+ include Aggregation::BaseExtension
54
55
  end
55
56
 
56
57
  ActiveSupport.run_load_hooks(:active_fedora, Base)
@@ -44,7 +44,7 @@ module ActiveFedora
44
44
  end
45
45
 
46
46
  def self.reinitialize_repo
47
- ActiveFedora.fedora.init_base_path
47
+ ActiveFedora.reset_fedora!
48
48
  end
49
49
 
50
50
  def self.log(message)
@@ -121,4 +121,7 @@ module ActiveFedora #:nodoc:
121
121
  # Raised when you try to set a URI to an already persisted Base object.
122
122
  class AlreadyPersistedError < ActiveFedoraError
123
123
  end
124
+
125
+ class DangerousAttributeError < ActiveFedoraError
126
+ end
124
127
  end
@@ -2,7 +2,6 @@ module ActiveFedora
2
2
  class Fedora
3
3
  def initialize(config)
4
4
  @config = config
5
- init_base_path
6
5
  end
7
6
 
8
7
  def host
@@ -26,11 +25,10 @@ module ActiveFedora
26
25
  end
27
26
 
28
27
  def connection
29
- # The InboundRelationConnection does provide more data, useful for
30
- # things like ldp:IndirectContainers, but it's imposes a significant
31
- # performance penalty on every request
32
- # @connection ||= InboundRelationConnection.new(CachingConnection.new(authorized_connection))
33
- @connection ||= CachingConnection.new(authorized_connection, omit_ldpr_interaction_model: true)
28
+ @connection ||= begin
29
+ init_base_path
30
+ build_connection
31
+ end
34
32
  end
35
33
 
36
34
  def clean_connection
@@ -46,14 +44,18 @@ module ActiveFedora
46
44
 
47
45
  # Call this to create a Container Resource to act as the base path for this connection
48
46
  def init_base_path
47
+ return if @initialized
48
+ connection = build_connection
49
+
49
50
  connection.head(root_resource_path)
50
51
  ActiveFedora::Base.logger.info "Attempted to init base path `#{root_resource_path}`, but it already exists" if ActiveFedora::Base.logger
52
+ @initialized = true
51
53
  false
52
54
  rescue Ldp::NotFound
53
55
  unless host.downcase.end_with?("/rest")
54
56
  ActiveFedora::Base.logger.warn "Fedora URL (#{host}) does not end with /rest. This could be a problem. Check your fedora.yml config"
55
57
  end
56
- connection.put(root_resource_path, BLANK).success?
58
+ @initialized = connection.put(root_resource_path, BLANK).success?
57
59
  end
58
60
 
59
61
  # Remove a leading slash from the base_path
@@ -61,6 +63,14 @@ module ActiveFedora
61
63
  @root_resource_path ||= base_path.sub(SLASH, BLANK)
62
64
  end
63
65
 
66
+ def build_connection
67
+ # The InboundRelationConnection does provide more data, useful for
68
+ # things like ldp:IndirectContainers, but it's imposes a significant
69
+ # performance penalty on every request
70
+ # @connection ||= InboundRelationConnection.new(CachingConnection.new(authorized_connection))
71
+ CachingConnection.new(authorized_connection, omit_ldpr_interaction_model: true)
72
+ end
73
+
64
74
  def authorized_connection
65
75
  options = {}
66
76
  options[:ssl] = ssl_options if ssl_options
@@ -1,10 +1,10 @@
1
1
  module ActiveFedora::File::Attributes
2
+ attr_writer :mime_type
3
+
2
4
  def mime_type
3
- fetch_mime_type
5
+ @mime_type ||= fetch_mime_type
4
6
  end
5
7
 
6
- delegate :mime_type=, to: :metadata
7
-
8
8
  def original_name
9
9
  @original_name ||= fetch_original_name
10
10
  end
@@ -25,7 +25,7 @@ module ActiveFedora::File::Attributes
25
25
  end
26
26
 
27
27
  def dirty_size
28
- content.size if content_changed? && content.respond_to?(:size)
28
+ content.size if changed? && content.respond_to?(:size)
29
29
  end
30
30
 
31
31
  def size
@@ -68,8 +68,8 @@ module ActiveFedora::File::Attributes
68
68
  end
69
69
 
70
70
  def fetch_mime_type
71
- return default_mime_type if new_record? && metadata.mime_type.blank?
72
- metadata.mime_type.first
71
+ return default_mime_type if new_record?
72
+ ldp_source.head.content_type
73
73
  end
74
74
 
75
75
  def fetch_original_name
@@ -22,13 +22,22 @@ module ActiveFedora::File::Streaming
22
22
  @headers = headers
23
23
  end
24
24
 
25
- def each
25
+ def each(no_of_requests_limit = 3, &block)
26
+ raise ArgumentError, 'HTTP redirect too deep' if no_of_requests_limit == 0
26
27
  Net::HTTP.start(uri.host, uri.port) do |http|
27
28
  request = Net::HTTP::Get.new uri, headers
28
29
  http.request request do |response|
29
- raise "Couldn't get data from Fedora (#{uri}). Response: #{response.code}" unless response.is_a?(Net::HTTPSuccess)
30
- response.read_body do |chunk|
31
- yield chunk
30
+ case response
31
+ when Net::HTTPSuccess
32
+ response.read_body do |chunk|
33
+ yield chunk
34
+ end
35
+ when Net::HTTPRedirection
36
+ no_of_requests_limit -= 1
37
+ @uri = URI(response["location"])
38
+ each(no_of_requests_limit, &block)
39
+ else
40
+ raise "Couldn't get data from Fedora (#{uri}). Response: #{response.code}"
32
41
  end
33
42
  end
34
43
  end
@@ -63,12 +63,6 @@ module ActiveFedora
63
63
  end
64
64
  end
65
65
 
66
- def save
67
- super.tap do
68
- metadata.save if metadata.changed?
69
- end
70
- end
71
-
72
66
  def described_by
73
67
  raise "#{self} isn't persisted yet" if new_record?
74
68
  links['describedby'].first
@@ -120,7 +114,6 @@ module ActiveFedora
120
114
  def attribute_will_change!(attr)
121
115
  if attr == 'content'
122
116
  changed_attributes['content'] = true
123
- elsif attr == 'type'
124
117
  else
125
118
  super
126
119
  end
@@ -145,15 +138,7 @@ module ActiveFedora
145
138
  end
146
139
 
147
140
  def changed?
148
- super || content_changed? || metadata_changed?
149
- end
150
-
151
- def metadata_changed?
152
- if new_record? || links['describedby'].blank?
153
- false
154
- else
155
- metadata.changed?
156
- end
141
+ super || content_changed?
157
142
  end
158
143
 
159
144
  def inspect
@@ -0,0 +1,8 @@
1
+ module ActiveFedora
2
+ module Orders
3
+ class CollectionProxy < ActiveFedora::Associations::CollectionProxy
4
+ attr_reader :association
5
+ delegate :append_target, :insert_target_at, :insert_target_id_at, :delete_at, to: :association
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,161 @@
1
+ module ActiveFedora::Orders
2
+ class ListNode
3
+ attr_reader :rdf_subject
4
+ attr_accessor :prev, :next, :target
5
+ attr_writer :next_uri, :prev_uri
6
+ attr_accessor :proxy_in, :proxy_for
7
+ def initialize(node_cache, rdf_subject, graph = RDF::Graph.new)
8
+ @rdf_subject = rdf_subject
9
+ @graph = graph
10
+ @node_cache = node_cache
11
+ Builder.new(rdf_subject, graph).populate(self)
12
+ end
13
+
14
+ # Returns the next proxy or a tail sentinel.
15
+ # @return [ActiveFedora::Orders::ListNode]
16
+ def next
17
+ @next ||=
18
+ if next_uri
19
+ node_cache.fetch(next_uri) do
20
+ node = self.class.new(node_cache, next_uri, graph)
21
+ node.prev = self
22
+ node
23
+ end
24
+ end
25
+ end
26
+
27
+ # Returns the previous proxy or a head sentinel.
28
+ # @return [ActiveFedora::Orders::ListNode]
29
+ def prev
30
+ @prev ||=
31
+ if prev_uri
32
+ node_cache.fetch(prev_uri) do
33
+ node = self.class.new(node_cache, prev_uri, graph)
34
+ node.next = self
35
+ node
36
+ end
37
+ end
38
+ end
39
+
40
+ # Graph representation of node.
41
+ # @return [ActiveFedora::Orders::ListNode::Resource]
42
+ def to_graph
43
+ g = Resource.new(rdf_subject)
44
+ g.proxy_for = target_uri
45
+ g.proxy_in = proxy_in.try(:uri)
46
+ g.next = self.next.try(:rdf_subject)
47
+ g.prev = prev.try(:rdf_subject)
48
+ g
49
+ end
50
+
51
+ # Object representation of proxyFor
52
+ # @return [ActiveFedora::Base]
53
+ def target
54
+ @target ||=
55
+ if proxy_for.present?
56
+ node_cache.fetch(proxy_for) do
57
+ ActiveFedora::Base.from_uri(proxy_for, nil)
58
+ end
59
+ end
60
+ end
61
+
62
+ def target_uri
63
+ RDF::URI(ActiveFedora::Base.id_to_uri(target_id)) if target_id
64
+ end
65
+
66
+ def target_id
67
+ MaybeID.new(@target.try(:id) || proxy_for).value
68
+ end
69
+
70
+ # Persists target if it's been accessed or set.
71
+ def save_target
72
+ if @target
73
+ @target.save
74
+ else
75
+ true
76
+ end
77
+ end
78
+
79
+ def proxy_in_id
80
+ MaybeID.new(@proxy_in.try(:id) || proxy_in).value
81
+ end
82
+
83
+ # Returns an ID whether or not the given value is a URI.
84
+ class MaybeID
85
+ attr_reader :uri_or_id
86
+ def initialize(uri_or_id)
87
+ @uri_or_id = uri_or_id
88
+ end
89
+
90
+ def value
91
+ id_composite.new([uri_or_id], translator).to_a.first
92
+ end
93
+
94
+ private
95
+
96
+ def id_composite
97
+ ActiveFedora::Associations::IDComposite
98
+ end
99
+
100
+ def translator
101
+ ActiveFedora::Base.translate_uri_to_id
102
+ end
103
+ end
104
+
105
+ # Methods necessary for association functionality
106
+ def destroyed?
107
+ false
108
+ end
109
+
110
+ def marked_for_destruction?
111
+ false
112
+ end
113
+
114
+ def valid?
115
+ true
116
+ end
117
+
118
+ def changed_for_autosave?
119
+ true
120
+ end
121
+
122
+ def new_record?
123
+ @target && @target.new_record?
124
+ end
125
+
126
+ private
127
+
128
+ attr_reader :next_uri, :prev_uri, :graph, :node_cache
129
+
130
+ class Builder
131
+ attr_reader :uri, :graph
132
+ def initialize(uri, graph)
133
+ @uri = uri
134
+ @graph = graph
135
+ end
136
+
137
+ def populate(instance)
138
+ instance.proxy_for = resource.proxy_for.first
139
+ instance.proxy_in = resource.proxy_in.first
140
+ instance.next_uri = resource.next.first
141
+ instance.prev_uri = resource.prev.first
142
+ end
143
+
144
+ private
145
+
146
+ def resource
147
+ @resource ||= Resource.new(uri, graph)
148
+ end
149
+ end
150
+
151
+ class Resource < ActiveTriples::Resource
152
+ property :proxy_for, predicate: ::RDF::Vocab::ORE.proxyFor, cast: false
153
+ property :proxy_in, predicate: ::RDF::Vocab::ORE.proxyIn, cast: false
154
+ property :next, predicate: ::RDF::Vocab::IANA.next, cast: false
155
+ property :prev, predicate: ::RDF::Vocab::IANA.prev, cast: false
156
+ def final_parent
157
+ parent
158
+ end
159
+ end
160
+ end
161
+ end
@@ -0,0 +1,264 @@
1
+ module ActiveFedora
2
+ module Orders
3
+ ##
4
+ # Ruby object representation of an ORE doubly linked list.
5
+ class OrderedList
6
+ include Enumerable
7
+ attr_reader :graph, :head_subject, :tail_subject
8
+ attr_writer :head, :tail
9
+ delegate :each, to: :ordered_reader
10
+ delegate :length, to: :to_a
11
+ # @param [::RDF::Enumerable] graph Enumerable where ORE statements are
12
+ # stored.
13
+ # @param [::RDF::URI] head_subject URI of head node in list.
14
+ # @param [::RDF::URI] tail_subject URI of tail node in list.
15
+ def initialize(graph, head_subject, tail_subject)
16
+ @graph = graph
17
+ @head_subject = head_subject
18
+ @tail_subject = tail_subject
19
+ @node_cache ||= NodeCache.new
20
+ @changed = false
21
+ tail
22
+ end
23
+
24
+ # @return [HeadSentinel] Sentinel for the top of the list. If not empty,
25
+ # head.next is the first element.
26
+ def head
27
+ @head ||= HeadSentinel.new(self, next_node: build_node(head_subject))
28
+ end
29
+
30
+ # @return [TailSentinel] Sentinel for the bottom of the list. If not
31
+ # empty, tail.prev is the first element.
32
+ def tail
33
+ @tail ||=
34
+ begin
35
+ if tail_subject
36
+ TailSentinel.new(self, prev_node: build_node(tail_subject))
37
+ else
38
+ head.next
39
+ end
40
+ end
41
+ end
42
+
43
+ # @param [Integer] key Position of the proxy
44
+ # @return [ListNode] Node for the proxy at the given position
45
+ def [](key)
46
+ list = ordered_reader.take(key + 1)
47
+ list[key]
48
+ end
49
+
50
+ # @return [ListNode] Last node in the list.
51
+ def last
52
+ if empty?
53
+ nil
54
+ else
55
+ tail.prev
56
+ end
57
+ end
58
+
59
+ # @param [Array<ListNode>] Nodes to remove.
60
+ # @return [OrderedList] List with node removed.
61
+ def -(other)
62
+ other.each do |node|
63
+ delete_node(node)
64
+ end
65
+ self
66
+ end
67
+
68
+ # @return [Boolean]
69
+ def empty?
70
+ head.next == tail
71
+ end
72
+
73
+ # @param [ActiveFedora::Base] target Target to append to list.
74
+ # @option [::RDF::URI, ActiveFedora::Base] :proxy_in Proxy in to
75
+ # assert on the created node.
76
+ def append_target(target, proxy_in: nil)
77
+ node = build_node(new_node_subject)
78
+ node.target = target
79
+ node.proxy_in = proxy_in
80
+ append_to(node, tail.prev)
81
+ end
82
+
83
+ # @param [Integer] loc Location to insert target at
84
+ # @param [ActiveFedora::Base] target Target to insert
85
+ def insert_at(loc, target, proxy_in: nil)
86
+ node = build_node(new_node_subject)
87
+ node.target = target
88
+ node.proxy_in = proxy_in
89
+ if loc == 0
90
+ append_to(node, head)
91
+ else
92
+ append_to(node, ordered_reader.take(loc).last)
93
+ end
94
+ end
95
+
96
+ # @param [Integer] loc Location to insert target at
97
+ # @param [String] proxy_for proxyFor to add
98
+ def insert_proxy_for_at(loc, proxy_for, proxy_in: nil)
99
+ node = build_node(new_node_subject)
100
+ node.proxy_for = proxy_for
101
+ node.proxy_in = proxy_in
102
+ if loc == 0
103
+ append_to(node, head)
104
+ else
105
+ append_to(node, ordered_reader.take(loc).last)
106
+ end
107
+ end
108
+
109
+ # @param [ListNode] node Node to delete
110
+ def delete_node(node)
111
+ node = ordered_reader.find { |x| x == node }
112
+ if node
113
+ prev_node = node.prev
114
+ next_node = node.next
115
+ node.prev.next = next_node
116
+ node.next.prev = prev_node
117
+ @changed = true
118
+ node
119
+ end
120
+ end
121
+
122
+ # @param [Integer] loc Index of node to delete.
123
+ def delete_at(loc)
124
+ return nil if loc.nil?
125
+ arr = ordered_reader.take(loc + 1)
126
+ delete_node(arr.last) if arr.length == loc + 1
127
+ end
128
+
129
+ # @param obj target of node to delete.
130
+ def delete_target(obj)
131
+ nodes_to_remove = ordered_reader.select { |list_node| obj.id == list_node.target_id }
132
+ nodes_to_remove.each { |list_node| delete_node(list_node) }
133
+ nodes_to_remove.last.try(:target)
134
+ end
135
+
136
+ # @return [Boolean] Whether this list was changed since instantiation.
137
+ def changed?
138
+ @changed
139
+ end
140
+
141
+ # Marks this ordered list as about to change. Useful for when changing
142
+ # proxies individually.
143
+ def order_will_change!
144
+ @changed = true
145
+ end
146
+
147
+ # @return [::RDF::Graph] Graph representation of this list.
148
+ def to_graph
149
+ ::RDF::Graph.new.tap do |g|
150
+ array = to_a
151
+ array.map(&:to_graph).each do |resource_graph|
152
+ g << resource_graph
153
+ end
154
+ end
155
+ end
156
+
157
+ # Marks this list as not changed.
158
+ def changes_committed!
159
+ @changed = false
160
+ end
161
+
162
+ # @return IDs of all ordered targets, in order
163
+ def target_ids
164
+ to_a.map(&:target_id)
165
+ end
166
+
167
+ # @return The node all proxies are a proxy in.
168
+ # @note If there are multiple proxy_ins this will log a warning and return
169
+ # the first.
170
+ def proxy_in
171
+ proxies = to_a.map(&:proxy_in_id).compact.uniq
172
+ if proxies.length > 1
173
+ ActiveFedora::Base.logger.warn "WARNING: List contains nodes aggregated under different URIs. Returning only the first." if ActiveFedora::Base.logger
174
+ end
175
+ proxies.first
176
+ end
177
+
178
+ private
179
+
180
+ attr_reader :node_cache
181
+
182
+ def append_to(source, append_node)
183
+ source.prev = append_node
184
+ if append_node.next
185
+ append_node.next.prev = source
186
+ source.next = append_node.next
187
+ else
188
+ self.tail = source
189
+ end
190
+ append_node.next = source
191
+ @changed = true
192
+ end
193
+
194
+ def ordered_reader
195
+ ActiveFedora::Aggregation::OrderedReader.new(self)
196
+ end
197
+
198
+ def build_node(subject = nil)
199
+ return nil unless subject
200
+ node_cache.fetch(subject) do
201
+ ActiveFedora::Orders::ListNode.new(node_cache, subject, graph)
202
+ end
203
+ end
204
+
205
+ def new_node_subject
206
+ node = ::RDF::URI("##{::RDF::Node.new.id}")
207
+ while node_cache.key?(node)
208
+ node = ::RDF::URI("##{::RDF::Node.new.id}")
209
+ end
210
+ node
211
+ end
212
+
213
+ class NodeCache
214
+ def initialize
215
+ @cache ||= {}
216
+ end
217
+
218
+ def fetch(uri)
219
+ @cache[uri] ||= yield if block_given?
220
+ end
221
+
222
+ def key?(key)
223
+ @cache.key?(key)
224
+ end
225
+ end
226
+
227
+ class Sentinel
228
+ attr_reader :parent
229
+ attr_writer :next, :prev
230
+ def initialize(parent, next_node: nil, prev_node: nil)
231
+ @parent = parent
232
+ @next = next_node
233
+ @prev = prev_node
234
+ end
235
+
236
+ attr_reader :next
237
+
238
+ attr_reader :prev
239
+
240
+ def nil?
241
+ true
242
+ end
243
+
244
+ def rdf_subject
245
+ nil
246
+ end
247
+ end
248
+
249
+ class HeadSentinel < Sentinel
250
+ def initialize(*args)
251
+ super
252
+ @next ||= TailSentinel.new(parent, prev_node: self)
253
+ end
254
+ end
255
+
256
+ class TailSentinel < Sentinel
257
+ def initialize(*args)
258
+ super
259
+ prev.next = self if prev && prev.next != self
260
+ end
261
+ end
262
+ end
263
+ end
264
+ end