Class: Resync::SortedResourceList

Inherits:
BaseResourceList show all
Defined in:
lib/resync/shared/sorted_resource_list.rb

Overview

An extension to BaseResourceList for resource lists that should be sorted by modification time.

Instance Attribute Summary collapse

Attributes inherited from BaseResourceList

#resources

Attributes inherited from Augmented

#links, #metadata

Instance Method Summary collapse

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_uriHash<URI, Array<Resource>> (readonly)

Returns resources grouped by URI. Order is not guaranteed.

Returns:

  • (Hash<URI, Array<Resource>>)

    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_urisArray<URI>

Returns the set of all URIs for which this list has resources. Order is not guaranteed.

Returns:

  • (Array<URI>)

    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.

Parameters:

  • uri (URI)

    the URI of the resource

Returns:

  • (Resource)

    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