class Sitemap
Attributes
collection_scope[R]
entries[R]
Public Class Methods
new(entries = [], **options) { |self| ... }
click to toggle source
# File lib/sitemap_simple/sitemap.rb, line 4 def initialize(entries = [], **options, &block) @entries = entries @collection_scope = options[:collection_scope] || :all yield self if block_given? end
Public Instance Methods
collection(resource, record_route, collection_route = nil)
click to toggle source
# File lib/sitemap_simple/sitemap.rb, line 14 def collection(resource, record_route, collection_route = nil) records = resource.send(collection_scope).inject [] do |m, record| m << Entry.new(record_route[record], lastmod: record.respond_to?(:updated_at) ? record.updated_at : nil ) end if collection_route @entries << collection_entry(collection_route, records) end @entries += records end
each_entry(&block)
click to toggle source
# File lib/sitemap_simple/sitemap.rb, line 26 def each_entry(&block) @entries.each &block end
entry(location, **options)
click to toggle source
# File lib/sitemap_simple/sitemap.rb, line 10 def entry(location, **options) @entries << Entry.new(location, **options) end
Private Instance Methods
collection_entry(location, records, options = {})
click to toggle source
# File lib/sitemap_simple/sitemap.rb, line 32 def collection_entry(location, records, options = {}) options.merge! lastmod: records.max_by(&:lastmod).lastmod if records.any? Entry.new(location, options) end