Class Atchoum::AutoRunner
In: lib/atchoum/auto_runner.rb
Parent: Object

Make the website script run as a standalone script. Hit the script with -? or without any arguments to get usage.

Methods

new   run   run  

Public Class methods

[Source]

    # File lib/atchoum/auto_runner.rb, line 12
12:     def initialize
13:       websites = []
14:       ObjectSpace.each_object(Class) do |klass|
15:         websites << klass if(klass < Website)
16:       end
17:       # TODO handled more then one website ?
18:       warn 'Supports only one website per script' if websites.size > 1
19:       @website = websites.first
20:     end

[Source]

    # File lib/atchoum/auto_runner.rb, line 8
 8:     def self.run
 9:       new.run
10:     end

Public Instance methods

Runs the script. Try -? to get help and usage.

[Source]

    # File lib/atchoum/auto_runner.rb, line 23
23:     def run
24:       conf = OpenStruct.new
25:       conf.port = 2000
26:       
27:       opts = OptionParser.new do |opts|
28:         opts.banner = "Usage: ruby #{$PROGRAM_NAME} [options]"
29:         opts.define_head "Because static websites need attention too!"
30:         opts.separator ""
31:         opts.separator "Options:"
32:         opts.on("-d", "--dump", "Dumps the website to HTML files") do
33:           conf.dump = true
34:         end
35:         opts.on("-s", "--server", "Starts webrick server") do
36:           conf.server = true
37:         end
38:         opts.on("-p", "--port NUM", "The webrick port to run on") { |conf.port| }
39:         opts.on_tail("-?", "--help", "Show this message") do
40:           puts opts
41:           return 0
42:         end
43:       end
44: 
45:       opts.parse! ARGV
46:       
47:       if conf.dump
48:         @website.new.to_files if conf.dump
49:       elsif conf.server
50:         Server.new($PROGRAM_NAME, conf.port).start if conf.server
51:       else
52:         puts opts
53:         return -1
54:       end
55:       0
56:     end

[Validate]