Class: Resync::Augmented
- Inherits:
-
Object
- Object
- Resync::Augmented
- Includes:
- XML::Mapping
- Defined in:
- lib/resync/shared/augmented.rb
Overview
Base class for elements augmented with ResourceSync-specific child elements.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#links ⇒ Array<Link>
Related links.
-
#metadata ⇒ Metadata
Metadata about this object.
Instance Method Summary collapse
-
#at_time ⇒ Time
Convenience accessor for the
at_timemetadata attribute. -
#change ⇒ Change
Convenience accessor for the
changemetadata attribute. -
#completed_time ⇒ Time
Convenience accessor for the
completed_timemetadata attribute. -
#from_time ⇒ Time
Convenience accessor for the
from_timemetadata attribute. -
#initialize(links: [], metadata: nil) ⇒ Augmented
constructor
Creates a new
Augmentedinstance with the specified links and metadata. -
#link_for(rel:) ⇒ Link
Shortcut to find the first link with the specified relation (in ResourceSync there often should be only one link with a particular relation).
-
#links_for(rel:) ⇒ Array<Link>
Finds links with the specified relation.
-
#until_time ⇒ Time
Convenience accessor for the
until_timemetadata attribute.
Constructor Details
#initialize(links: [], metadata: nil) ⇒ Augmented
Creates a new Augmented instance with the specified links and metadata.
48 49 50 51 |
# File 'lib/resync/shared/augmented.rb', line 48 def initialize(links: [], metadata: nil) self.links = links self. = end |
Instance Attribute Details
#links ⇒ Array<Link>
Returns related links.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/resync/shared/augmented.rb', line 12 class Augmented include ::XML::Mapping # ------------------------------------------------------------ # Class methods # ResourceSync-specific tags needing to be prefixed with +rs+ on output RS_TAGS = Set['ln', 'md'] private_constant :RS_TAGS # Adds the +rs+ namespace prefix 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 private_class_method :prefix_rewriter # ------------------------------------------------------------ # Attributes array_node :links, 'ln', class: Link, default_value: [], writer: method(:prefix_rewriter) object_node :metadata, 'md', class: Metadata, default_value: nil, writer: method(:prefix_rewriter) use_mapping :sitemapindex array_node :links, 'ln', class: Link, default_value: [], writer: method(:prefix_rewriter), sub_mapping: :_default object_node :metadata, 'md', class: Metadata, default_value: nil, writer: method(:prefix_rewriter), sub_mapping: :_default # ------------------------------------------------------------ # Initializer # 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. def initialize(links: [], metadata: nil) self.links = links self. = end # ------------------------------------------------------------ # Custom accessors # Sets the +links+ list. +nil+ is treated as an empty list. 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. def links_for(rel:) links.select { |l| l.rel == rel } 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. def link_for(rel:) links.find { |l| l.rel == rel } end # 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 def at_time .at_time if 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 def from_time .from_time if 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 def until_time .until_time if 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 def completed_time .completed_time if 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 def change .change if end end |
#metadata ⇒ Metadata
Returns metadata about this object.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/resync/shared/augmented.rb', line 12 class Augmented include ::XML::Mapping # ------------------------------------------------------------ # Class methods # ResourceSync-specific tags needing to be prefixed with +rs+ on output RS_TAGS = Set['ln', 'md'] private_constant :RS_TAGS # Adds the +rs+ namespace prefix 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 private_class_method :prefix_rewriter # ------------------------------------------------------------ # Attributes array_node :links, 'ln', class: Link, default_value: [], writer: method(:prefix_rewriter) object_node :metadata, 'md', class: Metadata, default_value: nil, writer: method(:prefix_rewriter) use_mapping :sitemapindex array_node :links, 'ln', class: Link, default_value: [], writer: method(:prefix_rewriter), sub_mapping: :_default object_node :metadata, 'md', class: Metadata, default_value: nil, writer: method(:prefix_rewriter), sub_mapping: :_default # ------------------------------------------------------------ # Initializer # 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. def initialize(links: [], metadata: nil) self.links = links self. = end # ------------------------------------------------------------ # Custom accessors # Sets the +links+ list. +nil+ is treated as an empty list. 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. def links_for(rel:) links.select { |l| l.rel == rel } 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. def link_for(rel:) links.find { |l| l.rel == rel } end # 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 def at_time .at_time if 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 def from_time .from_time if 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 def until_time .until_time if 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 def completed_time .completed_time if 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 def change .change if end end |
Instance Method Details
#at_time ⇒ Time
Convenience accessor for the at_time metadata attribute
80 81 82 |
# File 'lib/resync/shared/augmented.rb', line 80 def at_time .at_time if end |
#change ⇒ Change
Convenience accessor for the change metadata attribute
112 113 114 |
# File 'lib/resync/shared/augmented.rb', line 112 def change .change if end |
#completed_time ⇒ Time
Convenience accessor for the completed_time metadata attribute
104 105 106 |
# File 'lib/resync/shared/augmented.rb', line 104 def completed_time .completed_time if end |
#from_time ⇒ Time
Convenience accessor for the from_time metadata attribute
88 89 90 |
# File 'lib/resync/shared/augmented.rb', line 88 def from_time .from_time if end |
#link_for(rel:) ⇒ Link
Shortcut to find the first link with the specified relation (in ResourceSync there often should be only one link with a particular relation)
72 73 74 |
# File 'lib/resync/shared/augmented.rb', line 72 def link_for(rel:) links.find { |l| l.rel == rel } end |
#links_for(rel:) ⇒ Array<Link>
Finds links with the specified relation.
64 65 66 |
# File 'lib/resync/shared/augmented.rb', line 64 def links_for(rel:) links.select { |l| l.rel == rel } end |
#until_time ⇒ Time
Convenience accessor for the until_time metadata attribute
96 97 98 |
# File 'lib/resync/shared/augmented.rb', line 96 def until_time .until_time if end |