Class: Resync::CapabilityList

Inherits:
BaseResourceList show all
Includes:
XML::Mapping
Defined in:
lib/resync/capability_list.rb

Overview

A capability list. See section 9, “Advertising Capabilities”, in the ResourceSync specification.

Constant Summary collapse

CAPABILITY =

The capability provided by this type.

'capabilitylist'.freeze

Instance Attribute Summary

Attributes inherited from BaseResourceList

#resources

Attributes inherited from Augmented

#links, #metadata

Instance Method Summary collapse

Methods inherited from BaseResourceList

#capability, inherited, #metadata=, #pre_save, #resources_for, #resources_in

Methods inherited from Augmented

#at_time, #change, #completed_time, #from_time, #link_for, #links_for, #until_time

Constructor Details

#initialize(resources: [], links: [], metadata: nil) ⇒ CapabilityList

Creates a new BaseResourceList.

Parameters:

  • resources (Array<Resource>) (defaults to: [])

    The <url> or <sitemap> elements contained in this list. All resources must have a capability, and there can be no more than one resource for each specified capability.

  • links (Array<Link>) (defaults to: [])

    Related links (+<rs:ln>+).

  • metadata (Metadata) (defaults to: nil)

    Metadata about this list. The capability of the metadata must be ‘capabilitylist’.

Raises:

  • (ArgumentError)

    if a provided resource does not have a capability attribute.

  • (ArgumentError)

    if more than one provided resource has the same capability attribute.

  • (ArgumentError)

    if the specified metadata does not have the correct capability attribute.



28
29
30
31
# File 'lib/resync/capability_list.rb', line 28

def initialize(resources: [], links: [], metadata: nil)
  super(resources: resources, links: links, metadata: )
  @source_description = source_description_from(self.links)
end

Instance Method Details

#resource_for(capability:) ⇒ Resource

Gets the resource for the specified capability.

Parameters:

  • capability (String)

    The capability.

Returns:

  • (Resource)

    the resource providing the capability, or nil if there is no resource with that capability in this list.



49
50
51
# File 'lib/resync/capability_list.rb', line 49

def resource_for(capability:)
  @capabilities[capability]
end

#resources=(value) ⇒ Object

Sets the resources list. nil is treated as an empty list.

Raises:

  • (ArgumentError)

    if a provided resource does not have a capability attribute.

  • (ArgumentError)

    if more than one provided resource has the same capability attribute.



39
40
41
42
# File 'lib/resync/capability_list.rb', line 39

def resources=(value)
  @capabilities = to_capability_map(value || [])
  super(@capabilities.values)
end

#source_descriptionURI

Gets the URI of the description of the source whose capabilities are identified by this list.

Returns:

  • (URI)

    the URI of the description of the source whose capabilities are identified by this list. See section 8, “Describing the Source”, in the ResourceSync specification.



59
60
61
# File 'lib/resync/capability_list.rb', line 59

def source_description
  @source_description ||= source_description_from(links)
end