Class RubyRunRSS
In: lib/rubyrun/rubyrun_rss__.rb
Parent: Object

Methods

Constants

RUBYRUN_RSS_VERSION = '2.0'
RUBYRUN_RSS_CHANNEL_URL = 'http://www.rubysophic.com'
RUBYRUN_RSS_IMAGE_TITLE = 'Learn more about RubyRun from Rubysophic'
RUBYRUN_RSS_IMAGE_URL = 'http://www.rubysophic.com/images/logo.jpg'
RUBYRUN_RSS_FOLDER = 'rubyrun_rss'
RUBYRUN_RSS_PERF_SUMMARY_CHANNEL_TITLE = 'RubyRun: %s Performance Summary'
RUBYRUN_RSS_PERF_SUMMARY_CHANNEL_ITEM_FILENAME = 'perf_summary_item'
RUBYRUN_RSS_PERF_SUMMARY_CHANNEL_DESCRIPTION = 'RubyRun delivers up-to-the-minute performance summary of your application.'
RUBYRUN_RSS_PERF_SUMMARY_CHANNEL_FILENAME = 'perf_summary.xml'
RUBYRUN_RSS_PERF_SUMMARY_ITEM_TITLE = 'Performance summary at %s'
RUBYRUN_RSS_PERF_SUMMARY_ITEM_DESCRIPTION = 'Performance summary of %s at %s'

Public Class methods

Constructor of the class. RSS XML file and HTML files will be kept in the directory as specified

[Source]

    # File lib/rubyrun/rubyrun_rss__.rb, line 35
35:   def initialize (title, description, directory, rss_filename, html_filename)
36:     @title = title
37:     @description = description
38:     @directory = directory
39:     @rss_filename = rss_filename
40:     @html_filename = html_filename
41:     @apps_name = Rails::Configuration.new.root_path.split('/').last
42:     @rss_xml_destination = "#{@directory}/#{@rss_filename}"
43:     create_channel_content unless File::exists?(@rss_xml_destination)
44:     @rss = load_rss_content
45:   end

Public Instance methods

Add an item to the RSS channel

[Source]

    # File lib/rubyrun/rubyrun_rss__.rb, line 66
66:   def add_item (title, description, html_content)
67:     filename = "#{@html_filename}_#{Time.now.to_i}#{rand(1000000)}.html"
68:     File.open("#{@directory}/#{filename}", 'w') { |file| file.puts html_content }  
69:     item = RSS::Rss::Channel::Item.new
70:     item.title = sprintf(title, Time.now.strftime("%H:%M:%S"))
71:     item.description = sprintf(description, @apps_name, Time.now.strftime("%H:%M:%S"))
72:     item.link = "http://#{$rubyrun_host_with_port}/#{RUBYRUN_RSS_FOLDER}/#{filename}"
73:     remove_old_item(@rss) if @rss.items.length == $rubyrun_report_shift_age
74:     @rss.items << item
75:     File.open(@rss_xml_destination,"w") do |f|
76:       f.write(@rss)
77:     end    
78:   end

Create the RSS channel

[Source]

    # File lib/rubyrun/rubyrun_rss__.rb, line 48
48:   def create_channel_content
49:     content = RSS::Maker.make(RUBYRUN_RSS_VERSION) do |m|
50:       m.channel.title = sprintf(@title, @apps_name)
51:       m.channel.link = RUBYRUN_RSS_CHANNEL_URL
52:       m.channel.description = @description
53:       m.items.do_sort = true # sort items by date
54:       m.image.title = RUBYRUN_RSS_IMAGE_TITLE
55:       m.image.width = 140
56:       m.image.height = 25
57:       m.image.url = RUBYRUN_RSS_IMAGE_URL
58:     end
59:     File.open(@rss_xml_destination,"w") do |f|
60:       f.write(content)
61:     end
62:     content.to_s
63:   end

[Validate]