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'

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

Methods inherited from Augmented

#link_for, #links_for

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)
  @source_descripton = source_description_from(links)
  super(resources: resources, links: links, metadata: )
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.



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

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
43
# File 'lib/resync/capability_list.rb', line 39

def resources=(value)
  resources = value || []
  @capabilities = to_capability_map(resources)
  @resources = @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.



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

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