Class: ActionView::Helpers::AtomFeedHelper::AtomFeedBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/action_view/helpers/atom_feed_helper.rb

Instance Method Summary collapse

Constructor Details

#initialize(xml, view) ⇒ AtomFeedBuilder

Returns a new instance of AtomFeedBuilder.



70
71
72
# File 'lib/action_view/helpers/atom_feed_helper.rb', line 70

def initialize(xml, view)
  @xml, @view = xml, view
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *arguments) ⇒ Object (private)



105
106
107
# File 'lib/action_view/helpers/atom_feed_helper.rb', line 105

def method_missing(method, *arguments)
  @xml.__send__(method, *arguments)
end

Instance Method Details

#entry(record, options = {}) ⇒ Object

Creates an entry tag for a specific record and prefills the id using class and id.

Options:

  • :updated: Time of update. Defaults to the created_at attribute on the record if one such exists.

  • :published: Time first published. Defaults to the updated_at attribute on the record if one such exists.

  • :url: The URL for this entry. Defaults to the polymorphic_url for the record.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/action_view/helpers/atom_feed_helper.rb', line 86

def entry(record, options = {})
  @xml.entry do 
    @xml.id("tag:#{@view.request.host_with_port}:#{record.class}#{record.id}")

    if options[:published] || (record.respond_to?(:created_at) && record.created_at)
      @xml.published((options[:published] || record.created_at).xmlschema)
    end

    if options[:updated] || (record.respond_to?(:updated_at) && record.updated_at)
      @xml.updated((options[:updated] || record.updated_at).xmlschema)
    end

    @xml.link(:rel => 'alternate', :type => 'text/html', :href => options[:url] || @view.polymorphic_url(record))

    yield @xml
  end
end

#updated(date_or_time = nil) ⇒ Object

Accepts a Date or Time object and inserts it in the proper format. If nil is passed, current time in UTC is used.



75
76
77
# File 'lib/action_view/helpers/atom_feed_helper.rb', line 75

def updated(date_or_time = nil)
  @xml.updated((date_or_time || Time.now.utc).xmlschema)
end