class Devserver::CLI

Public Class Methods

determine_app_root() click to toggle source

Pretend that we are checking for rails by checking for config/boot.rb we'll even do something smart for ourselves by chdir .. if ../config/boot.rb exists. “smart for ourselves” is the operative phrase

@return [String] the current app root path if we think this is a rails dir, else nil

# File lib/devserver/cli.rb, line 47
def self.determine_app_root
  if(File.exist?('config/boot.rb'))
    return Dir.pwd
  elsif(File.exist?('../config/boot.rb'))
    Dir.chdir('..')
    return Dir.pwd
  else
    return nil
  end
end
load_defaults_from_yaml() click to toggle source

Load defaults from a devserver.yaml file located in config/

# File lib/devserver/cli.rb, line 59
def self.load_defaults_from_yaml
  configfile ="#{@@app_root}/config/devserver.yml"
  if File.exists?(configfile) then
    @@default_settings[:configfile] = configfile
    temp = YAML.load_file(configfile)
    if temp.class == Hash
      temp.each do |key,value|
        @@default_settings[key.to_sym] = value
        @@default_settings_source[key.to_sym] = configfile
      end
    end
  end   
end
set_defaults() click to toggle source

sets defaults for the class

# File lib/devserver/cli.rb, line 28
def self.set_defaults
  if(!(@@app_root = self.determine_app_root))
    @@is_rails_dir = false
    @@app_root = '.'
  end
  @@default_settings[:port] = 3000
  @@default_settings[:environment] = 'development'
  @@default_settings[:log_file] = "#{@@app_root}/log/devserver.log"
  @@default_settings[:pid_file] = "#{@@app_root}/tmp/pids/devserver.pid"
  @@default_settings[:mode] = 'start'
  @@default_settings[:server] = 'thin'
  self.load_defaults_from_yaml
end

Public Instance Methods

about() click to toggle source
# File lib/devserver/cli.rb, line 121
def about
  rails_warning
  puts "Devserver Version #{VERSION}: Provides a wrapper around passenger, thin or mongrel for local ruby on rails development."
end
command() click to toggle source
# File lib/devserver/cli.rb, line 187
def command
  rails_warning
  the_server = Devserver::CommandManager.new(options)
  gem_warning(the_server)
  if(options[:start])
    puts "start command: #{the_server.command('start')}"
  end
  if(options[:stop])
    puts "stop command: #{the_server.command('stop')}"
  end
  if(options[:debug])
    puts "debug command: #{the_server.command('debug')}"
  end
end
debug() click to toggle source
# File lib/devserver/cli.rb, line 156
def debug
  rails_error
  the_server = Devserver::CommandManager.new(options)
  gem_error(the_server)
  if(the_server.is_port_open?)
    puts "Another process is running on Port: #{the_server.port}"
    puts "Running stop command: #{the_server.command(stop)}"
    the_server.stop_devserver
  end
  the_server.start_devserver('debug')
end
defaults() click to toggle source
# File lib/devserver/cli.rb, line 127
def defaults
  rails_warning
  print_defaults
end
gem_error(server) click to toggle source

exits with error if the specified web server gem is not available

# File lib/devserver/cli.rb, line 94
def gem_error(server)
  if(!server.command_available?)
    puts "ERROR: The #{server.server} gem does not appear to be installed"
    exit(1)
  end
end
gem_warning(server) click to toggle source

prints out a warning message if the specified web server gem is not available

# File lib/devserver/cli.rb, line 102
def gem_warning(server)
  if(!server.command_available?)
    puts "WARNING:  The #{server.server} gem does not appear to be installed"
  end
end
print_defaults() click to toggle source

prints out the default settings

rails_error() click to toggle source

exits with error if current dir does not appear to be a rails dir

# File lib/devserver/cli.rb, line 86
def rails_error
  if(!@@is_rails_dir)
    puts "ERROR: #{Dir.pwd} does not appear to be a rails application directory"
    exit(1)
  end
end
rails_warning() click to toggle source

prints out a warning message if current dir does not appear to be a rails dir

# File lib/devserver/cli.rb, line 79
def rails_warning
  if(!@@is_rails_dir)
    puts "WARNING: #{Dir.pwd} does not appear to be a rails application directory"
  end
end
start() click to toggle source
# File lib/devserver/cli.rb, line 138
def start
  rails_error
  the_server = Devserver::CommandManager.new(options)
  gem_error(the_server)
  if(the_server.is_port_open?)
    puts "Another process is running on Port: #{the_server.port}"
    puts "Running stop command: #{the_server.command('stop')}"
    the_server.stop_devserver
  end
  the_server.start_devserver
end
stop() click to toggle source
# File lib/devserver/cli.rb, line 170
def stop
  rails_error
  gem_error(the_server)
  the_server = Devserver::CommandManager.new(options)
  gem_error(the_server)
  the_server.stop_devserver      
end