Class: Monorail::ApplicationGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/monorail/appgen.rb

Instance Method Summary collapse

Constructor Details

#initializeApplicationGenerator

Returns a new instance of ApplicationGenerator.



42
43
# File 'lib/monorail/appgen.rb', line 42

def initialize
end

Instance Method Details

#generate_directoryObject

nodoc: This hardcodes the monorail directory structure. Obviously not satisfactory. We’ll need some softer way of doing this eventually. WE ARE ASSUMING the directory structure of the gem. We expect to be in directory lib/monorail, and we look to copy the directory found at ../../skel relative to ourself.



60
61
62
63
64
65
66
67
68
69
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
# File 'lib/monorail/appgen.rb', line 60

def generate_directory
  target = File.expand_path( @options.dir )
  puts "Creating monorail app in directory: #{target}"

  if (@options.erase)
    $stderr.write "*** Erase the target directory [yN]? "
    gets and chomp
p "...#{$_}"
    unless $_ =~ /\Ay/i
      puts "Exiting..."
      exit
    end
    FileUtils.rm_rf target
  end

  skel = File.dirname( __FILE__ ) + "/../../skel/."
  FileUtils.cp_r( skel, target )

  File.open( target + "/monorail_config.rb", "w") {|f|
    f.puts "# Monorail Config file"
    f.puts "# Generated at #{Time.now}"
    f.puts "#"
    f.puts

    f.puts <<EOF
Monorail::Request::directory_alias "/public", "#{target}/public", :directory, false
Monorail::Request::directory_alias "/", "#{target}/c", :monorail, false

Monorail::Request::set_default_pathinfo "/public/index.html"

Monorail::Request::use_sessions true

Monorail::Request::verbose true
Monorail::Request::debug true
EOF

    puts "Done."
    puts "To see your new app:"
    puts " Type: monorail server #{(@options.dir == ".") ? "" : "-d #{@options.dir}"}"
    puts " Browse to: http://127.0.0.1:8900"
  }
end

#parse_argumentsObject



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/monorail/appgen.rb', line 103

def parse_arguments
  @options = OpenStruct.new
  @options.dir = '.'
  @options.erase = false

  opts = OptionParser.new {|opts|
    opts.banner = "Usage: monorail application [options]"

    opts.separator ""
    opts.separator "Options summary:"

    opts.on("-d", "--dir [DIR]", "generate a monorail application in directory",
          "     default: the current directory") do |d|
      @options.dir = d
    end

    opts.on("--[no-]erase", "erase the target directory before copying files",
      "    default: do not erase") {|erase|
        @options.erase = erase
    }

    # Options summary
    opts.on_tail("-h", "--help", "Show this message") {
      puts opts
      exit
    }

    # Version
    opts.on_tail("--version", "Show version") {
      puts Version
      exit
    }


  }

  opts.parse!(ARGV)

end

#runObject



46
47
48
49
# File 'lib/monorail/appgen.rb', line 46

def run
  parse_arguments
  generate_directory
end