Class: Gossip::TracCrony

Inherits:
Crony
  • Object
show all
Defined in:
lib/gossip/cronies/trac.rb

Overview

Right now, TracCrony is kind of a hack. It uses trac-admin(1) to edit a wiki page. If configured to do so, Trac will add wiki changes into the Timeline. OK, it’s more than “kind of” a hack.

Note that you must be running a command that uses a Trac crony on the Trac server itself.

An alternative would be to use Mechanize. This was easier for now.

Instance Attribute Summary

Attributes inherited from Crony

#is_bff_by_default, #user_choices

Instance Method Summary collapse

Methods inherited from Crony

#add_bff_choice, #checked, #df, #initialize, #is_bff?, #is_bff_by_default?, #postprocess_user_choices

Constructor Details

This class inherits a constructor from Gossip::Crony

Instance Method Details

#add_configuration_choices(builder) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/gossip/cronies/trac.rb', line 30

def add_configuration_choices(builder)
  builder.add_choice(:trac_admin_path,
                     :default => checked(:default_trac_admin_path)) { | command_line |
    command_line.uses_option("--trac-admin-path PATH", 
                             "Absolute pathname to trac-admin(1).",
                             df(:default_trac_admin_path)
                             )
  }
  
  builder.add_choice(:trac_environment_path,
                     :default => checked(:default_environment_path)) { | command_line |
    command_line.uses_option("--trac-environment-path PATH", 
                             "Your Trac environment.",
                             df(:default_environment_path)
                             )
  }
  
  builder.add_choice(:trac_page_name,
                     :default => checked(:default_page_name)) { | command_line |
    command_line.uses_option("--trac-page-name PAGE", 
                             "A Trac wiki page to receive the message.",
                             df(:default_page_name)
                             )
  }
  
  builder.add_choice(:trac_content_file,
                     :default => checked(:default_content_file)) { | command_line |
    command_line.uses_option("--trac-content-file FILE", 
                             "A file to use as the content of the page.",
                             df(:default_content_file)
                             )
  }
  
end

#command_line_descriptionObject



24
25
26
27
28
# File 'lib/gossip/cronies/trac.rb', line 24

def command_line_description
    ["-T", "--trac",
     "Control display to Trac timeline.",
     "Defaults to #{is_bff_by_default?}."]
end

#hear(scandal, details) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/gossip/cronies/trac.rb', line 65

def hear(scandal, details)
  trac_admin = @user_choices[:trac_admin_path]
  env = @user_choices[:trac_environment_path]
  page = @user_choices[:trac_page_name]
  file = @user_choices[:trac_content_file]
  current = File.exist?(file) ? File.read(file) : ""
  File.open(file, "w") do | io |
    io.puts(scandal)
    io.puts(details.gsub(/$/, '[[BR]]'))
    io.puts('---------------')
    io.puts current
  end
  exec = "#{trac_admin} #{env} wiki import #{page} #{file}"
  `#{exec}`
end

#nameObject



21
# File 'lib/gossip/cronies/trac.rb', line 21

def name; "trac"; end

#symbolObject



22
# File 'lib/gossip/cronies/trac.rb', line 22

def symbol; :trac; end