class Resync::Augmented
Base class for elements augmented with ResourceSync-specific child elements.
@!attribute [rw] links
@return [Array<Link>] related links.
@!attribute [rw] metadata
@return [Metadata] metadata about this object.
Constants
- RS_TAGS
ResourceSync-specific tags needing to be prefixed with
rs
on output
Public Class Methods
Creates a new Augmented
instance with the specified links and metadata.
@param links [Array<Link>] related links (i.e. +<rs:ln>+). @param metadata [Metadata] metadata about this resource.
# File lib/resync/shared/augmented.rb, line 48 def initialize(links: [], metadata: nil) self.links = links self.metadata = metadata end
Private Class Methods
Adds the rs
namespace prefix
# File lib/resync/shared/augmented.rb, line 23 def self.prefix_rewriter(obj, xml, default_obj_to_xml) default_obj_to_xml.call(obj, xml) xml.each_element do |e| e.name = "rs:#{e.name}" if RS_TAGS.include?(e.name) end end
Public Instance Methods
Convenience accessor for the at_time
metadata attribute @return [Time] the datetime at which assembling a resource list
began (including resource list indices, resource dumps, etc.)
@see Metadata#at_time
# File lib/resync/shared/augmented.rb, line 80 def at_time metadata.at_time if metadata end
Convenience accessor for the change
metadata attribute @return [Change] the type of change to a resource reported in
a change list (including change list indices, change dumps, etc.)
@see Metadata#change
# File lib/resync/shared/augmented.rb, line 112 def change metadata.change if metadata end
Convenience accessor for the completed_time
metadata attribute @return [Time] the datetime at which assembling a resource list
ended (including resource list indices, resource dumps, etc.)
@see Metadata#completed_time
# File lib/resync/shared/augmented.rb, line 104 def completed_time metadata.completed_time if metadata end
Convenience accessor for the from_time
metadata attribute @return [Time] the beginning of the time range represented by
a change list (including change list indices, change dumps, etc.)
@see Metadata#from_time
# File lib/resync/shared/augmented.rb, line 88 def from_time metadata.from_time if metadata end
Shortcut to find the first link with the specified relation (in ResourceSync there often should be only one link with a particular relation) @param rel [String] the relation. @return [Link] the first link having that relation, or nil if none exists.
# File lib/resync/shared/augmented.rb, line 72 def link_for(rel:) links.find { |l| l.rel == rel } end
Sets the links
list. nil
is treated as an empty list.
# File lib/resync/shared/augmented.rb, line 57 def links=(value) @links = value || [] end
Finds links with the specified relation. @param rel [String] the relation. @return [Array<Link>] those links having that relation, or an empty array if none exist.
# File lib/resync/shared/augmented.rb, line 64 def links_for(rel:) links.select { |l| l.rel == rel } end
Convenience accessor for the until_time
metadata attribute @return [Time] the end of the time range represented by
a change list (including change list indices, change dumps, etc.)
@see Metadata#until_time
# File lib/resync/shared/augmented.rb, line 96 def until_time metadata.until_time if metadata end