public
Last active

Ruby development stack presentation

  • Download Gist
Gemfile
Ruby
1 2 3 4 5 6 7 8 9 10 11
# encoding: utf-8
 
# Gemfile
source 'https://rubygems.org/'
 
gem 'rake' # up to date version
gem 'rack', '~> 1.4.1' # pessimistic version
gem 'thin', '= 1.5' # exact version
group :test do
gem 'rspec'
end
Rakefile
Ruby
1 2 3 4 5 6 7 8 9 10 11
# encoding: utf-8
 
# Rakefile
# example from: http://rake.rubyforge.org/
task default: [:test]
 
desc "Run all tests"
task :test do
$stdout.puts "---> Running all tests"
ruby "test/unittest.rb"
end
bundle_config.yml
YAML
1 2
---
BUNDLE_PATH: vendor/bundle
bundle_install_example.sh
Shell
1 2 3 4 5 6
# install all gems in ./vendor/bundle
$ bundle install --path=vendor/bundle
# install gems' binaries in ./bin
$ bundle install --binstubs
# use the installed bin instead of `bundle exec`
$ bin/rake
bundler_ruby_usage.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14
# encoding: utf-8
 
# Bundler must be in the global load path.
require 'bundler'
# Require the gems declared in the Gemfile
# you can require by groups
Bundler.require(:default, :test)
 
# or you can do:
# Bundler.setup(:default, :test)
# require 'rake'
 
# Use the gems
Rake::Task['test'].invoke
gem_install.sh
Shell
1
$ gem install rake --version 0.3.1 --force
irb_example.sh
Shell
1 2 3 4 5 6 7 8
$ irb
irb(main):001:0> IRB.rc_file
=> "/Users/jhbabon/.irbrc"
irb(main):002:0> hello = lambda { |p| puts "Hello #{p}" }
=> #<Proc:0x007fdc14873398@(irb):22 (lambda)>
irb(main):003:0> hello.call('world')
Hello world
=> nil
rails_generators_examples.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
$ bundle exec rails g
Usage: rails generate GENERATOR [args] [options]
 
General options:
-h, [--help] # Print generator's options and usage
-p, [--pretend] # Run but do not make any changes
-f, [--force] # Overwrite files that already exist
-s, [--skip] # Skip files that already exist
-q, [--quiet] # Suppress status output
 
Please choose a generator below.
 
Rails:
controller
generator
helper
mailer
migration
model
observer
responders_controller
scaffold
 
ActiveRecord:
active_record:devise
# and more...
rails_task_example.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12
# set the Rails environment with an shell env variable
$ RAILS_ENV=staging bundle exec rake db:migrate
# show all tasks
$ bundle exec rake -T
rake db:create # Create the database from config/database.yml for the current Rails.env (use db:cr...
rake db:drop # Drops the database for the current Rails.env (use db:drop:all to drop all databases)
rake db:migrate # Migrate the database (options: VERSION=x, VERBOSE=false).
rake log:clear # Truncates all *.log files in log/ to zero bytes
rake middleware # Prints out your Rack middleware stack
rake notes # Enumerate all annotations (use notes:optimize, :fixme, :todo for focus)
rake routes # Print out all defined routes in match
# many more...
rake_usage_example.sh
Shell
1 2 3 4
# call default task
$ bundle exec rake
# or a explicit task
$ bundle exec rake test

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.