天天看點

Rails 的 Rake Task List

今天有人問到怎麼清 log ,結果我一直記得 Rails 的 Rakefile 可以幫你 log,不過還是忘記怎麼打了,查了一下發現隻要 rake log:clear 即可。

在 Rails 裡面,預設了很多 rake 指令可以幫你輕鬆達成許多任務。這裡列出所有的 Rails Rake Task List。基本上,要叫出 Task List 隻要在 Rails 資料夾下面打 rake --task ,或是 rake -T ,他就會自動幫我們叫出 Rails 下面所有的 Rake Task List。

DB 處理方面的 Task

  1. rake db:fixtures:load # Load fixtures into the current environment's database. Load specific fixtures using FIXTURES=x,y
  2. rake db:migrate

    # Migrate the database through scripts in db/migrate. Target specific version with VERSION=x

    使用 Database 的 migrate 功能,他會把 db/migrate 裡面寫的 script 寫入到 DB 裡面。

  3. rake db:schema:dump # Create a db/schema.rb file that can be portably used against any DB supported by AR
  4. rake db:schema:load # Load a schema.rb file into the database
  5. rake db:sessions:clear

    # Clear the sessions table

    假設你的 Session 是利用 CGI::Session::ActiveRecordStore 存在 DB 裡面的時候,這個指令可以清理裡面Session 的 Table

  6. rake db:sessions:create

    # Creates a sessions table for use with CGI::Session::ActiveRecordStore

  7. rake db:structure:dump # Dump the database structure to a SQL file
  8. rake db:test:clone # Recreate the test database from the current environment's database schema
  9. rake db:test:clone_structure # Recreate the test databases from the development structure
  10. rake db:test:prepare # Prepare the test database and load the schema
  11. rake db:test:purge # Empty the test database

自動建立 RDoc

  1. rake doc:app # Build the app HTML Files
  2. rake doc:clobber_app # Remove rdoc products
  3. rake doc:clobber_plugins # Remove plugin documentation
  4. rake doc:clobber_rails # Remove rdoc products
  5. rake doc:plugins # Generate documation for all installed plugins
  6. rake doc:rails # Build the rails HTML Files
  7. rake doc:reapp # Force a rebuild of the RDOC files
  8. rake doc:rerails # Force a rebuild of the RDOC files

清理 log file

  1. rake log:clear # Truncates all *.log files in log/ to zero bytes

Rails 版本 Freeze 跟 Update

  1. rake rails:freeze:edge # Lock to latest Edge Rails or a specific revision with REVISION=X (ex: REVISION=4021) or a tag with TAG=Y (ex: TAG=rel_1-1-0)
  2. rake rails:freeze:gems # Lock this application to the current gems (by unpacking them into vendor/rails)
  3. rake rails:unfreeze # Unlock this application from freeze of gems or edge and return to a fluid use of system gems
  4. rake rails:update # Update both configs, scripts and public/javascripts from Rails
  5. rake rails:update:configs # Update boot/config.rb from your current rails install
  6. rake rails:update:javascripts # Update your javascripts from your current rails install
  7. rake rails:update:scripts # Add new scripts to the application script/ directory

報導現在的 code state

  1. rake stats # Report code statistics (KLOCs, etc) from the application

Unit Testing 方面

  1. rake test # Test all units and functionals
  2. rake test:functionals # Run tests for functionalsdb:test:prepare
  3. rake test:integration # Run tests for integrationdb:test:prepare
  4. rake test:plugins # Run tests for pluginsenvironment
  5. rake test:recent # Run tests for recentdb:test:prepare
  6. rake test:uncommitted # Run tests for uncommitteddb:test:prepare
  7. rake test:units # Run tests for unitsdb:test:prepare

清理 tmp/ 底下的暫存檔

  1. rake tmp:cache:clear # Clears all files and directories in tmp/cache
  2. rake tmp:clear # Clear session, cache, and socket files from tmp/
  3. rake tmp:create # Creates tmp directories for sessions, cache, and sockets
  4. rake tmp:sessions:clear # Clears all files in tmp/sessions
  5. rake tmp:sockets:clear # Clears all files in tmp/sockets