Rake to odpowiednik Uniksowego make
. Wykorzystywany jest do wykonywania drobnych zadań administracyjnych, koniecznych podczas pisania aplikacji opartych na bazach danych. Najczęściej wykonywanym poleceniem jest rake db:migrate
, ale są również i inne:
chopin:demo_app sqbell$ rake -T (in /Users/sqbell/Workspace/rails_projects/demo_app) rake about # List versions of all Rails frameworks and the environment rake db:create # Create the database from config/database.yml for the current Rails.env (use db:create:all to crea... rake db:drop # Drops the database for the current Rails.env (use db:drop:all to drop all databases) rake db:fixtures:load # Load fixtures into the current environment's database. rake db:migrate # Migrate the database (options: VERSION=x, VERBOSE=false). rake db:migrate:status # Display status of migrations rake db:rollback # Rolls the schema back to the previous version (specify steps w/ STEP=n). rake db:schema:dump # Create a db/schema.rb file that can be portably used against any DB supported by AR rake db:schema:load # Load a schema.rb file into the database rake db:seed # Load the seed data from db/seeds.rb rake db:setup # Create the database, load the schema, and initialize with the seed data (use db:reset to also dro... rake db:structure:dump # Dump the database structure to an SQL file rake db:version # Retrieves the current schema version number rake doc:app # Generate docs for the app -- also availble doc:rails, doc:guides, doc:plugins (options: TEMPLATE=... 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 notes:custom # Enumerate a custom annotation, specify with ANNOTATION=CUSTOM rake rails:template # Applies the template supplied by LOCATION=/path/to/template rake rails:update # Update both configs and public/javascripts from Rails (or use just update:javascripts or update:c... rake routes # Print out all defined routes in match order, with names. rake secret # Generate a cryptographically secure secret key (this is typically used to generate a secret for c... rake stats # Report code statistics (KLOCs, etc) from the application rake test # Runs test:units, test:functionals, test:integration together (also available: test:benchmark, tes... rake test:recent # Run tests for {:recent=>"test:prepare"} / Test recent changes rake test:uncommitted # Run tests for {:uncommitted=>"test:prepare"} / Test changes since last checkin (only Subversion a... rake time:zones:all # Displays all time zones, also available: time:zones:us, time:zones:local -- filter with OFFSET pa... rake tmp:clear # Clear session, cache, and socket files from tmp/ (narrow w/ tmp:sessions:clear, tmp:cache:clear, ... rake tmp:create # Creates tmp directories for sessions, cache, sockets, and pids
chopin:demo_app sqbell$ rake stats (in /Users/sqbell/Workspace/rails_projects/demo_app) +----------------------+-------+-------+---------+---------+-----+-------+ | Name | Lines | LOC | Classes | Methods | M/C | LOC/M | +----------------------+-------+-------+---------+---------+-----+-------+ | Controllers | 86 | 61 | 2 | 7 | 3 | 6 | | Helpers | 4 | 4 | 0 | 0 | 0 | 0 | | Models | 2 | 2 | 1 | 0 | 0 | 0 | | Libraries | 0 | 0 | 0 | 0 | 0 | 0 | | Integration tests | 0 | 0 | 0 | 0 | 0 | 0 | | Functional tests | 49 | 39 | 1 | 0 | 0 | 0 | | Unit tests | 12 | 9 | 2 | 0 | 0 | 0 | +----------------------+-------+-------+---------+---------+-----+-------+ | Total | 153 | 115 | 6 | 7 | 1 | 14 | +----------------------+-------+-------+---------+---------+-----+-------+ Code LOC: 67 Test LOC: 48 Code to Test Ratio: 1:0.7
chopin:demo_app sqbell$ rake routes (in /Users/sqbell/Workspace/rails_projects/demo_app) users GET /users(.:format) {:action=>"index", :controller=>"users"} POST /users(.:format) {:action=>"create", :controller=>"users"} new_user GET /users/new(.:format) {:action=>"new", :controller=>"users"} edit_user GET /users/:id/edit(.:format) {:action=>"edit", :controller=>"users"} user GET /users/:id(.:format) {:action=>"show", :controller=>"users"} PUT /users/:id(.:format) {:action=>"update", :controller=>"users"} DELETE /users/:id(.:format) {:action=>"destroy", :controller=>"users"}
Można też wyspecyfikować kontroler:
[sqbell@sqbell-arch AgnosticAnisotropy]$ CONTROLLER=projects rake routes projects GET /projects(.:format) projects#index POST /projects(.:format) projects#create new_project GET /projects/new(.:format) projects#new edit_project GET /projects/:id/edit(.:format) projects#edit project GET /projects/:id(.:format) projects#show PUT /projects/:id(.:format) projects#update DELETE /projects/:id(.:format) projects#destroy salesforecasts /salesforecasts(.:format) projects#salesforecasts project_staff /project_staff(.:format) projects#project_staff
dpl11122:mototop sqbell$ rake notes app/controllers/motorbikes_controller.rb: * [ 39] [TODO] add price sorting logic here * [129] [TODO] find_or_create? app/models/motorbike.rb: * [200] [FIXME] Goes through all orders - not good
dpl11122:mototop sqbell$ rake db:migrate:status database: db/development.sqlite3 Status Migration ID Migration Name -------------------------------------------------- up 20120113100001 Devise create users up 20120114100002 Create makes up 20120114100003 Create models up 20120114100004 Create photos up 20120114100005 Add attachment photo to photo up 20120114100006 Create motorbikes up 20120120172238 Create ckeditor assets up 20120122204039 Create messages up 20120123162658 Add avatar id to motorbikes up 20120125090620 Create categories up 20120125132204 Add trigger to categories up 20120127113059 Create statuses up 20120127153152 Remove counter cache from categories up 20120129183724 Add stuff to motorbikes up 20120201085224 Create versions up 20120201090636 Add object changes to versions up 20120203215231 Create message templates up 20120213092807 Add modals to statuses up 20120213140228 Add read to motorbikes up 20120229083441 Add status id to messages up 20120321143316 Add radio input to drive up 20120424112859 Add user created to models up 20120424112939 Add user created to