Skip to content

Instantly share code, notes, and snippets.

@seanbehan
Created February 24, 2012 23:31
Show Gist options
  • Select an option

  • Save seanbehan/1904572 to your computer and use it in GitHub Desktop.

Select an option

Save seanbehan/1904572 to your computer and use it in GitHub Desktop.
Misc Code
# ERB YAML Template
def database_configuration
require 'erb'
YAML::load(ERB.new(IO.read(paths["config/database"].first)).result)
end
# HEREDOC Syntax
TEMPLATE = <<-HTML # :nodoc:
<!DOCTYPE html>
<html>
<head></head>
</html>
HTML
# Option Parser
require 'optparse'
OptionParser.new { |op|
op.on('-p port', 'set the port (default is 4567)') { |val| set :port, Integer(val) }
op.on('-o addr', 'set the host (default is 0.0.0.0)') { |val| set :bind, val }
op.on('-e env', 'set the environment (default is development)') { |val| set :environment, val.to_sym }
op.on('-s server', 'specify rack server/handler (default is thin)') { |val| set :server, val }
op.on('-x', 'turn on the mutex lock (default is off)') { set :lock, true }
}.parse!(ARGV.dup)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment