Class: DamageControl::StandardPersister

Inherits:
Object
  • Object
show all
Defined in:
lib/damagecontrol/standard_persister.rb

Overview

Persists standard stuff like changesets, diffs and RSS. Typically used within a block passed to a Poller. See App.

Instance Method Summary collapse

Instance Method Details

#save_changesets(project, changesets) ⇒ Object

Save the changesets to disk as YAML



12
13
14
15
# File 'lib/damagecontrol/standard_persister.rb', line 12

def save_changesets(project, changesets)
  Log.info "Saving changesets for #{project.name}"
  changesets.accept(project.changesets_persister)
end

#save_diffs(project, changesets) ⇒ Object

Get the diffs for each change and save them.



18
19
20
21
22
23
# File 'lib/damagecontrol/standard_persister.rb', line 18

def save_diffs(project, changesets)
  Log.info "Getting diffs for #{project.name}"
  dp = DamageControl::Visitor::DiffPersister.new(project.scm, project.name)
  changesets.accept(dp)
  Log.info "Saved diffs for #{project.name}"
end

#save_rss(project) ⇒ Object

Save RSS to disk. The RSS spec says max 15 items in a channel, (www.chadfowler.com/ruby/rss/) We’ll get upto the latest 15 changesets and turn them into RSS.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/damagecontrol/standard_persister.rb', line 28

def save_rss(project)
  Log.info "Generating RSS for #{project.name}"
  last_15_changesets = project.changesets_persister.load_upto(project.changesets_persister.latest_identifier, 15)
  RSS::Maker.make("2.0") do |rss|
    FileUtils.mkdir_p(File.dirname(project.changesets_rss_file))
    File.open(project.changesets_rss_file, "w") do |io|
      rss_writer = DamageControl::Visitor::RssWriter.new(
        rss,
        "Changesets for #{project.name}",
        "http://localhost:4712/", # TODO point to web version of changeset
        project.name, 
        project.tracker || Tracker::Null.new, 
        project.scm_web || SCMWeb::Null.new        
      )
      last_15_changesets.accept(rss_writer)
      io.write(rss.to_rss)
    end
  end
  Log.info "Saved RSS for #{project.name} to #{project.changesets_rss_file}"
end