Class: Resync::SortedResourceList
- Inherits:
-
BaseResourceList
- Object
- Augmented
- BaseResourceList
- Resync::SortedResourceList
- Defined in:
- lib/resync/shared/sorted_resource_list.rb
Overview
An extension to BaseResourceList
for resource lists that should be sorted by modification time.
Direct Known Subclasses
ChangeDump, ChangeDumpIndex, ChangeDumpManifest, ChangeList, ChangeListIndex
Instance Attribute Summary collapse
-
#resources_by_uri ⇒ Hash<URI, Array<Resource>>
readonly
Resources grouped by URI.
Attributes inherited from BaseResourceList
Attributes inherited from Augmented
Instance Method Summary collapse
-
#all_uris ⇒ Array<URI>
The set of all URIs for which this list has resources.
-
#latest_for(uri:) ⇒ Resource
The resource with the most recent modified time for the specified URI.
-
#resources=(value) ⇒ Object
Sets the
resources
list, sorting the resources by modification time.
Methods inherited from BaseResourceList
#capability, inherited, #initialize, #metadata=, #pre_save, #resource_for, #resources_for
Methods inherited from Augmented
#initialize, #link_for, #links_for
Constructor Details
This class inherits a constructor from Resync::BaseResourceList
Instance Attribute Details
#resources_by_uri ⇒ Hash<URI, Array<Resource>> (readonly)
Returns resources grouped by URI. Order is not guaranteed.
24 25 26 |
# File 'lib/resync/shared/sorted_resource_list.rb', line 24 def resources_by_uri @resources_by_uri end |
Instance Method Details
#all_uris ⇒ Array<URI>
Returns the set of all URIs for which this list has resources. Order is not guaranteed.
36 37 38 |
# File 'lib/resync/shared/sorted_resource_list.rb', line 36 def all_uris @resources_by_uri.keys end |
#latest_for(uri:) ⇒ Resource
Returns the resource with the most recent modified time for the specified URI.
29 30 31 32 |
# File 'lib/resync/shared/sorted_resource_list.rb', line 29 def latest_for(uri:) uri = XML.to_uri(uri) @resources_by_uri[uri].last end |
#resources=(value) ⇒ Object
Sets the resources
list, sorting the resources by modification time. (nil
is treated as an empty list.) Resources without modification times will be sorted to the end.
14 15 16 17 |
# File 'lib/resync/shared/sorted_resource_list.rb', line 14 def resources=(value) super(sorted(value)) @resources_by_uri = by_uri(@resources) end |