Class: Ramaze::Bin::Console

Inherits:
Object show all
Defined in:
lib/ramaze/bin/console.rb

Overview

Allows the user to enter an IRB like session that takes advantage of everything provided by Ramaze.

Usage

 ramaze console
 ramaze console /path/to/app/start.rb

Author:

Since:

Constant Summary

Description =

String containing the description of this command.

Since:

  • 21-07-2011

'Starts an IRB session with Ramaze loaded into the session'
"Starts an IRB session and loads Ramaze into the session. All specified Rack\noptions are ignored and environment variables are passed to IRB.\n\nUsage:\nramaze console [DIR] [OPTIONS]\n\nExample:\nramaze console\nramaze console /home/foobar/ramaze/start.rb\n".strip

Instance Method Summary (collapse)

Constructor Details

- (Console) initialize

Creates a new instance of the command and sets all the options.

Author:

  • Yorick Peterse

Since:

  • 21-07-2011



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/ramaze/bin/console.rb', line 43

def initialize
  @options = OptionParser.new do |opt|
    opt.         = 
    opt.summary_indent = '  '

    opt.separator "\nOptions:\n"

    opt.on('-h', '--help', 'Shows this help message') do
      puts @options
      exit
    end
  end
end

Instance Method Details

- (Object) run(argv = [])

Runs the command based on the given command line arguments.

Parameters:

  • argv (Array) (defaults to: [])

    An array of command line arguments.

Author:

  • Yorick Peterse

Since:

  • 21-07-2011



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/ramaze/bin/console.rb', line 64

def run(argv = [])
  @options.parse!(argv)

  start_file = argv.delete_at(0)
  start_file = File.join(Dir.pwd, 'start.rb') if start_file.nil?

  if File.directory?(start_file)
    start_file = File.join(start_file, 'start.rb')
  end

  if !File.exist?(start_file)
    abort "The file #{start_file} does not exist"
  end

  start_file             = Pathname.new(start_file).realpath.to_s
  Ramaze.options.started = true

  require(start_file)

  IRB.start
  puts 'Ramazement has ended, go in peace.'
end