-
Notifications
You must be signed in to change notification settings - Fork 0
Ruby cheatsheet
Tak Tran edited this page Jun 20, 2013
·
17 revisions
To start with debugger
script/server --debugger # rails 2
rake server --debugger # rails 3
Rails application name
Rails.application.class.name
Run tests
bundle exec rake spec
bundle exec spec --color spec/models/something.rb
Pending tests
pending "Not done yet"
Focus specs
# spec_helper.rb
RSpec.configure do |conf|
conf.filter_run_including :focus => true
end
# spec
describe "something", :focus => true do
end
Rake task to run a particular spec file
namespace "spec" do
desc "Run individual spec. Can also pass in a line number."
task :run, :spec_file, :line_number do |_, args|
run_spec_cmd = if args.line_number.nil?
"bundle exec ruby -S rspec --color #{args.spec_file}"
else
"bundle exec ruby -S rspec --color -l #{args.line_number} #{args.spec_file}"
end
sh run_spec_cmd
end
end
To search for _id
in MongoHub
{"_id": ObjectId("222222")}
Delete all with a condition
Model.delete_all(:attr => attr)
From mongomapper querying)
patients = Patient.where( :last_name.gte => 'A', :last_name.lt => 'B' ).count
#=> 1803
From mongodb querying
db.myCollection.find( { a : { $gt : 3 } } );
See https://gist.github.com/428105
Modified from optionparser.
require 'optparse'
SCRIPT_NAME = "rename.rb"
OPTIONS = {}
optparse = OptionParser.new do|opts|
# Set a banner, displayed at the top
# of the help screen.
opts.banner = "Usage: #{SCRIPT_NAME} [options] file1 file2..."
# Define the options, and what they do
OPTIONS[:verbose] = false
opts.on( '-v', '--verbose', 'Output more information' ) do
OPTIONS[:verbose] = true
end
OPTIONS[:quick] = false
opts.on( '-q', '--quick', 'Perform the task quickly' ) do
OPTIONS[:quick] = true
end
OPTIONS[:logfile] = nil
opts.on( '-l', '--logfile FILE', 'Write log to FILE' ) do|file|
OPTIONS[:logfile] = file
end
# This displays the help screen, all programs are
# assumed to have this option.
opts.on( '-h', '--help', 'Display this screen' ) do
puts opts
exit
end
end
# Parse the command-line. Remember there are two forms
# of the parse method. The 'parse' method simply parses
# ARGV, while the 'parse!' method parses ARGV and removes
# any options found there, as well as any parameters for
# the options. What's left is the list of files to process.
optparse.parse!
puts "Being verbose" if OPTIONS[:verbose]
puts "Being quick" if OPTIONS[:quick]
puts "Logging to file #{OPTIONS[:logfile]}" if OPTIONS[:logfile]
ARGV.each do|f|
puts "Argv: #{f}..."
end
cap [name] deploy:setup
cap [name] deploy
# Invoke commands
cap invoke
http://cheat.errtheblog.com/s/capistrano/
- Referencing incorrect repository url when deploying - if repository has changed, need to delete
/shared/cache-copy
-
fatal: The remote end hung up unexpectedly
- need to add repo to~/.ssh/authorized_keys
file. Can do agit clone
from the server to do this.