Top Level Namespace
Defined Under Namespace
Modules: Rave Classes: Logger, Range
Instance Method Summary collapse
-
#appcfg_update(args) ⇒ Object
Does an appcfg update to deploy the tmp/war folder to appengine.
-
#cleanup_war(args) ⇒ Object
Runs warbler’s cleanup to get rid of the .war file and the tmp/war folder.
- #config_file_contents(options) ⇒ Object
-
#create_robot(args) ⇒ Object
Creates a project for a robot.
-
#create_war(args) ⇒ Object
Runs warbler to package up the robot then does some cleanup that is specific to App Engine: => Deletes the complete JRuby jar from both the app’s lib folder and the frozen warbler gem, and replaces them with a broken up version => Changes the file path json-jruby TODO: Not sure why this is necessary, but it doesn’t run on appengine without it.
-
#display_usage ⇒ Object
Display usage for rave command.
- #html_file_contents(name, id, image_url) ⇒ Object
- #robot_file_contents(module_name) ⇒ Object
- #run_file_contents(robot_class_name, robot_file) ⇒ Object
-
#start_robot(args) ⇒ Object
Starts up rack based on the config.ru file in the working directory Note that this is of limited use right now, because robots have to run on appengine.
Instance Method Details
#appcfg_update(args) ⇒ Object
Does an appcfg update to deploy the tmp/war folder to appengine
2 3 4 5 6 7 8 9 |
# File 'lib/commands/appcfg.rb', line 2 def appcfg_update(args) Rake.application.standard_exception_handling do Rake.application.init Rave::Task.new task(:default => "rave:appcfg_update") Rake.application.top_level end end |
#cleanup_war(args) ⇒ Object
Runs warbler’s cleanup to get rid of the .war file and the tmp/war folder
21 22 23 24 25 26 27 28 |
# File 'lib/commands/war.rb', line 21 def cleanup_war(args) Rake.application.standard_exception_handling do Rake.application.init Rave::Task.new task(:default => "rave:clean") Rake.application.top_level end end |
#config_file_contents(options) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/commands/create.rb', line 118 def config_file_contents() <<-CONFIG robot: id: #{[:id]} name: #{[:name]} image_url: #{[:image_url]} profile_url: #{[:profile_url]} version: #{[:version]} appcfg: version: 1 # Uncomment this section to add gems required by your robot. # They will unpacked in your project at appengine deploy time # gems: # - some_gem # Replace this with the name of the gem you require # - some_other_gem # Replace this with the name of the gem you require CONFIG end |
#create_robot(args) ⇒ Object
Creates a project for a robot. Args are:
> robot_name (required)
> image_url= (optional)
> profile_url=profileurl.com/ (optional)
e.g. rave my_robot image_url= profile_url=appropriate-casey.appspot.com/profile.json
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 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 64 65 66 67 68 |
# File 'lib/commands/create.rb', line 8 def create_robot(args) robot_name = args.first module_name = robot_name.split(/_|-/).collect { |word| word.capitalize }.join robot_class_name = "#{module_name}::Robot" = { :name => robot_name, :version => 1, :id => "#{robot_name}@appspot.com" } args[1, args.length-1].each do |arg| key, value = arg.split("=").collect { |part| part.strip } [key.to_sym] = value end dir = File.join(".", robot_name) if File.exist? dir puts "Directory #{dir}/ already exists. Exiting..." exit end lib = File.join(dir, "lib") config_dir = File.join(dir, "config") file = File.join(dir, "robot.rb") run = File.join(dir, "config.ru") config = File.join(dir, "config.yaml") public_folder = File.join(dir, "public") html = File.join(public_folder, "index.html") #Create the project dir puts "Creating directory #{File.(dir)}" Dir.mkdir(dir) puts "Creating robot class #{File.(file)}" #Make the base robot class File.open(file, "w") do |f| f.puts robot_file_contents(module_name) end # Make the rackup run file. puts "Creating rackup config file #{File.(run)}" File.open(run, "w") do |f| f.puts run_file_contents(robot_class_name, file) end # Make up the yaml config file. puts "Creating configuration file #{File.(config)}" File.open(config, "w") do |f| f.puts config_file_contents() end #Make the public folder for static resources puts "Creating public folder" Dir.mkdir(public_folder) # Make up the html index file. puts "Creating html index file #{File.(html)}" File.open(html, "w") do |f| f.puts html_file_contents(robot_name, [:id], [:image_url]) end #Create lib directory puts "Creating lib directory #{File.(lib)}" Dir.mkdir(lib) end |
#create_war(args) ⇒ Object
Runs warbler to package up the robot then does some cleanup that is specific to App Engine:
> Deletes the complete JRuby jar from both the app’s lib folder and
the frozen warbler gem, and replaces them with a broken up version
> Changes the file path json-jruby
TODO: Not sure why this is necessary, but it doesn't run on appengine without it
11 12 13 14 15 16 17 18 |
# File 'lib/commands/war.rb', line 11 def create_war(args) Rake.application.standard_exception_handling do Rake.application.init Rave::Task.new task(:default => "rave:create_war") Rake.application.top_level end end |
#display_usage ⇒ Object
Display usage for rave command
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/commands/usage.rb', line 2 def display_usage puts "Useage: rave [create | server | war] [robot_name] [options]" puts "'create' generates a Google Wave robot client stub application." puts "e.g." puts "rave create my_robot image_url=http://my_robot.appspot.com/image.png profile_url=http://my_robot.appspot.com/" puts "'server' launches the robot" puts "e.g." puts "rave server" puts "'war' creates a war file suitable for deploying to Google AppEngine" puts "e.g." puts "rave war" puts "'appengine_deploy' deploys the tmp/war folder to Google AppEngine" puts "e.g." puts "rave appengine_deploy" puts "'cleanup' removes the .war file and the tmp/war staging directory" puts "e.g." puts "rave cleanup" end |
#html_file_contents(name, id, image_url) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/commands/create.rb', line 136 def html_file_contents(name, id, image_url) img_tag = image_url ? "\n <img src=\"#{image_url}\" alt=\"#{name} icon\" />\n" : "" <<-HTML <html> <head> <title>#{name}</title> </head> <body> <h1>#{name}</h1> #{img_tag} <p>This is a Google Wave robot using <a href="http://github.com/diminish7/rave">Rave</a> running in JRuby. Use this robot in your Google Waves by adding <em>#{id}</em> as a participant</p> <img src="http://code.google.com/appengine/images/appengine-silver-120x30.gif" alt="Powered by Google App Engine" /> </body> </html> HTML end |
#robot_file_contents(module_name) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/commands/create.rb', line 70 def robot_file_contents(module_name) <<-ROBOT require 'rubygems' require 'rave' module #{module_name} class Robot < Rave::Models::Robot #Define handlers here: # e.g. if the robot should act on a DOCUMENT_CHANGED event: # # def document_changed(event, context) # #Do some stuff # end # # Events are: # # WAVELET_BLIP_CREATED, WAVELET_BLIP_REMOVED, WAVELET_PARTICIPANTS_CHANGED, # WAVELET_TIMESTAMP_CHANGED, WAVELET_TITLE_CHANGED, WAVELET_VERSION_CHANGED, # BLIP_CONTRIBUTORS_CHANGED, BLIP_DELETED, BLIP_SUBMITTED, BLIP_TIMESTAMP_CHANGED, # BLIP_VERSION_CHANGED, DOCUMENT_CHANGED, FORM_BUTTON_CLICKED # # If you want to name your event handler something other than the default name, # or you need to have more than one handler for an event, you can register handlers # in the robot's constructor: # # def initialize(options={}) # super # register_handler(Rave::Models::Event::DOCUMENT_CHANGED, :custom_doc_changed_handler) # end # # def custom_doc_changed_handler(event, context) # #Do some stuff # end # # Note: Don't forget to call super if you define #initialize end end ROBOT end |
#run_file_contents(robot_class_name, robot_file) ⇒ Object
111 112 113 114 115 116 |
# File 'lib/commands/create.rb', line 111 def run_file_contents(robot_class_name, robot_file) <<-CONFIG require '#{File.basename(robot_file).chomp(File.extname(robot_file))}' run #{robot_class_name}.instance CONFIG end |
#start_robot(args) ⇒ Object
Starts up rack based on the config.ru file in the working directory Note that this is of limited use right now, because robots have to run on appengine. Better to test locally with the appengine sdk
4 5 6 7 8 |
# File 'lib/commands/server.rb', line 4 def start_robot(args) cmd = (RUBY_PLATFORM == 'java') ? "jruby -S rackup" : "rackup" cmd += " " + args.join(" ") if args exec(cmd) end |