breaking into the unknown…

what is rake in rails

Leave a comment

rake is command line utility of rails. All commands available for rails are listed here . writing custom rake task is explained in this post . Below is the definition given for it in rails doc.

“Rake is Ruby Make, a standalone Ruby utility that replaces the Unix utility ‘make’, and uses a ‘Rakefile’ and .rake files to build up a list of tasks. In Rails, Rake is used for common administration tasks, especially sophisticated ones that build off of each other.”

Putting in simple word : “rake will execute different tasks(basically a set of ruby code) specified in any file with .rake extension from comandline.” .

rake is a gem in itself and installation dependency of rails i,e whenever you install a rails rake gem get installed along with it.

rails provide a number of inbuilt task like : db:create, db:migrate etc, you have been familiar with. You can define your own task (see here) also. list of all the task can be seen with below command.

$ rake -T #below is the list of task with small description of what they do. when you install a gem say cucumber or rcov or any othet, if they have defined any rake task it will get listed here.basically below is the list of all task available to you : the built one, those provided by installed gems or custome task wriiten by you
rake about                                              # List versions of all Rails frameworks and the environment
rake assets:clean                                       # Remove compiled assets
rake assets:precompile                                  # Compile all the assets named in config.assets.precompile
rake cucumber                                           # Alias for cucumber:ok
rake cucumber:all                                       # Run all features
rake cucumber:ok                                        # Run features that should pass
rake cucumber:rerun                                     # Record failing features and run only them if any exist
rake cucumber:wip                                       # Run features that are being worked on
rake db:create                                          # Create the database from DATABASE_URL or config/database.yml
rake db:drop                                            # Drops the database using DATABASE_URL or the current Rails.env
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
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
rake db:structure:dump                                  # Dump the database structure to db/structure.sql.
rake db:version                                         # Retrieves the current schema version number
rake doc:app                                            # Generate docs for the app — also available doc:rails
rake jquery_ui_themes:import:google_cdn[version,theme]  # Import themes from Google CDN
rake jquery_ui_themes:import:themeroller[path,name]     # Import jQuery themeroller theme
rake loanpath:on_db_refresh                             # Actions to do after the db refresh
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 paperclip:clean                                    # Cleans out invalid attachments.
rake paperclip:refresh                                  # Refreshes both metadata and thumbnails.
rake paperclip:refresh:metadata                         # Regenerates content_type/size metadata for a given CLASS
rake paperclip:refresh:missing_styles                   # Regenerates missing thumbnail styles for all classes using Paperclip.
rake paperclip:refresh:thumbnails                       # Regenerates thumbnails for a given CLASS
rake rails:template                                     # Applies the template supplied by LOCATION=(/path/to/template) or URL
rake rails:update                                       # Update configs and some other initially generated files
rake rails_admin:disable_initializer                    # Disable rails_admin initializer / Disable rails_admin initializer
rake rails_admin:install                                # Install rails_admin / Install rails_admin
rake rails_admin:prepare_ci_env                         # CI env for Travis / CI env for Travis
rake rails_admin:uninstall                              # Uninstall rails_admin / Uninstall rails_admin
rake routes                                             # Print out all defined routes in match order, with names.
rake secret                                             # Generate a cryptographically secure secret key
rake spec                                               # Run all specs in spec directory (excluding plugin specs)
rake spec:controllers                                   # Run the code examples in spec/controllers
rake spec:helpers                                       # Run the code examples in spec/helpers
rake spec:lib                                           # Run the code examples in spec/lib
rake spec:mailers                                       # Run the code examples in spec/mailers
rake spec:models                                        # Run the code examples in spec/models
rake spec:rcov                                          # Run all specs with rcov
rake spec:requests                                      # Run the code examples in spec/requests
rake spec:routing                                       # Run the code examples in spec/routing
rake spec:views                                         # Run the code examples in spec/views
rake stats                                              # Report code statistics (KLOCs, etc) from the application
rake time:zones:all                                     # Displays all time zones, also available: time:zones:us
rake tmp:clear                                          # Clear session, cache, and socket files from tmp/
rake tmp:create                                         # Creates tmp directories for sessions, cache, sockets, and pids

In the above command we have passed -T option which list all the tasks for us. list of other available option for rake can be listed with –help option as below

$ rake –help
rake [-f rakefile] {options} targets…

Options are …
–backtrace=[OUT]            Enable full backtrace.  OUT can be stderr (default) or stdout.
–comments                   Show commented tasks only
–job-stats [LEVEL]          Display job statistics. LEVEL=history displays a complete job list
–rules                      Trace the rules resolution.
–suppress-backtrace PATTERN Suppress backtrace lines matching regexp PATTERN. Ignored if –trace is on.
-A, –all                        Show all tasks, even uncommented ones
-D, –describe [PATTERN]         Describe the tasks (matching optional PATTERN), then exit.
-e, –execute CODE               Execute some Ruby code and exit.
-E, –execute-continue CODE      Execute some Ruby code, then continue with normal task processing.
-f, –rakefile [FILE]            Use FILE as the rakefile.
-G, –no-system, –nosystem      Use standard project Rakefile search paths, ignore system wide rakefiles.
-g, –system                     Using system wide (global) rakefiles (usually ‘~/.rake/*.rake’).
-I, –libdir LIBDIR              Include LIBDIR in the search path for required modules.
-j, –jobs [NUMBER]              Specifies the maximum number of tasks to execute in parallel. (default:2)
-m, –multitask                  Treat all tasks as multitasks.
-n, –dry-run                    Do a dry run without executing actions.
-N, –no-search, –nosearch      Do not search parent directories for the Rakefile.
-P, –prereqs                    Display the tasks and dependencies, then exit.
-p, –execute-print CODE         Execute some Ruby code, print the result, then exit.
-q, –quiet                      Do not log messages to standard output.
-r, –require MODULE             Require MODULE before executing rakefile.
-R, –rakelibdir RAKELIBDIR,     Auto-import any .rake files in RAKELIBDIR. (default is ‘rakelib’)
-s, –silent                     Like –quiet, but also suppresses the ‘in directory’ announcement.
-t, –trace=[OUT]                Turn on invoke/execute tracing, enable full backtrace. OUT can be stderr (default) or stdout.
-T, –tasks [PATTERN]            Display the tasks (matching optional PATTERN) with descriptions, then exit.
-v, –verbose                    Log message to standard output.
-V, –version                    Display the program version.
-W, –where [PATTERN]            Describe the tasks (matching optional PATTERN), then exit.
-X, –no-deprecation-warnings    Disable the deprecation warnings.
-h, -H, –help                   Display this help message.

Author: arunyadav4u

over 7 years experience in web development with Ruby on Rails.Involved in all stage of development lifecycle : requirement gathering, planing, coding, deployment & Knowledge transfer. I can adept to any situation, mixup very easily with people & can be a great friend.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s