Class: RubyRunRSS
Constant Summary collapse
- 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 =
'Report for %s at %s'
- RUBYRUN_RSS_PERF_SUMMARY_ITEM_DESCRIPTION =
'Performance summary of %s (%s) at %s'
Instance Method Summary collapse
-
#add_item(title, description, html_content) ⇒ Object
Add an item to the RSS channel.
-
#create_channel_content ⇒ Object
Create the RSS channel.
-
#initialize(title, description, directory, rss_filename, html_filename) ⇒ RubyRunRSS
constructor
Constructor of the class.
Constructor Details
#initialize(title, description, directory, rss_filename, html_filename) ⇒ RubyRunRSS
Constructor of the class. RSS XML file and HTML files will be kept in the directory as specified
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rubyrun/rubyrun_rss__.rb', line 35 def initialize (title, description, directory, rss_filename, html_filename) @title = title @description = description @directory = directory @rss_filename = rss_filename @html_filename = html_filename @apps_name = Rails::Configuration.new.root_path.split('/').last @rss_xml_destination = "#{@directory}/#{@rss_filename}" create_channel_content unless File::exists?(@rss_xml_destination) end |
Instance Method Details
#add_item(title, description, html_content) ⇒ Object
Add an item to the RSS channel
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/rubyrun/rubyrun_rss__.rb', line 65 def add_item (title, description, html_content) filename = "#{@html_filename}_#{Time.now.to_i}#{rand(1000000)}.html" File.open("#{@directory}/#{filename}", 'w') { |file| file.puts html_content } item = RSS::Rss::Channel::Item.new item.title = sprintf(title, "#{$rubyrun_startup_id_type} #{$rubyrun_startup_id}",Time.now.strftime("%H:%M:%S")) item.description = sprintf(description, @apps_name, "#{$rubyrun_startup_id_type} #{$rubyrun_startup_id}", Time.now.strftime("%H:%M:%S")) item.link = "http://#{$rubyrun_host_with_port}/#{RUBYRUN_RSS_FOLDER}/#{filename}" acquire_lock rss = load_rss_content remove_old_item(rss) if rss.items.length == $rubyrun_report_shift_age rss.items << item File.open(@rss_xml_destination,"w") do |f| f.write(rss) end release_lock end |
#create_channel_content ⇒ Object
Create the RSS channel
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rubyrun/rubyrun_rss__.rb', line 47 def create_channel_content content = RSS::Maker.make(RUBYRUN_RSS_VERSION) do |m| m.channel.title = sprintf(@title, @apps_name) m.channel.link = RUBYRUN_RSS_CHANNEL_URL m.channel.description = @description m.items.do_sort = true # sort items by date m.image.title = RUBYRUN_RSS_IMAGE_TITLE m.image.width = 140 m.image.height = 25 m.image.url = RUBYRUN_RSS_IMAGE_URL end File.open(@rss_xml_destination,"w") do |f| f.write(content) end content.to_s end |