Class: Sake

Inherits:
Object
  • Object
show all
Defined in:
lib/sake.rb,
lib/help.rb,
lib/server.rb

Overview

Show all Sake tasks (but no local Rake tasks), optionally only those matching a pattern.

$ sake -T
$ sake -T db

Show tasks in a Rakefile, optionally only those matching a pattern.

$ sake -T file.rake
$ sake -T file.rake db

Install tasks from a Rakefile, optionally specifying specific tasks.

$ sake -i Rakefile
$ sake -i Rakefile db:remigrate
$ sake -i Rakefile db:remigrate routes

Examine the source of a Rake task.

$ sake -e routes

You can also examine the source of a task not yet installed.

$ sake -e Rakefile db:remigrate

Uninstall an installed task.

$ sake -u db:remigrate

Stores the source of a task into a pastie (pastie.caboo.se). Returns the url of the pastie to stdout.

$ sake -P routes

Can be passed one or more tasks.

Invoke a Sake task.

$ sake <taskname>

Some Sake tasks may depend on tasks which exist only locally.

For instance, you may have a db:version sake task which depends on the ‘environment’ Rake task. The ‘environment’ Rake task is one defined by Rails to load its environment. This db:version task will work when your current directory is within a Rails app because Sake knows how to find Rake tasks. This task will not work, however, in any other directory (unless a task named ‘environment’ indeed exists).

Sake can also serve its tasks over a network by launching a Mongrel handler. Pass the -S switch to start Sake in server mode.

$ sake -S

You can, of course, specify a port.

$ sake -S -p 1111

You can also daemonize your server for long term serving fun.

$ sake -S -d

Defined Under Namespace

Modules: Help, Server, Store, Version Classes: Task, TasksArray, TasksFile

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Sake

The ‘application’ class, this is basically the controller which decides what to do then executes.



83
84
85
86
87
# File 'lib/sake.rb', line 83

def initialize(args)
  @args = args
  Rake.application
  Rake.application.options.silent = true
end

Instance Method Details

#runObject

This method figures out what to do and does it. Basically a big switch. Note the seemingly random return statements: return if you don’t want run_rake invoked. Some actions do want it invoked, however, so they don’t return (like version, which prints a Sake version then trusts Rake to do likewise).



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/sake.rb', line 96

def run
  ##
  # Show Sake tasks in the store or in a file, optionally searching for a pattern.
  # $ sake -T 
  # $ sake -T db
  # $ sake -T file.rake
  # $ sake -T file.rake db
  if (index = @args.index('-T')) || @args.empty?
    begin
      tasks   = TasksFile.parse(@args[index + 1]).tasks
      pattern = @args[index + 2]
    rescue
      tasks   = Store.tasks.sort
      pattern = index ? @args[index + 1] : nil
    end

    return show_tasks(tasks, pattern)

  ##
  # Install a Rakefile or a single Rake task
  # $ sake -i Rakefile
  # $ sake -i Rakefile db:migrate
  elsif index = @args.index('-i')
    return install(index)

  ##
  # Uninstall one or more Rake tasks from the Sake store.
  elsif index = @args.index('-u')
    return uninstall(index)

  ##
  # Examine a Rake task
  #   $ sake -e routes
  #   $ sake -e Rakefile db:remigrate
  elsif index = @args.index('-e')
    die examine(index)

  ##
  # Save one or more tasks to Pastie (http://pastie.caboos.se) 
  # then return the new Pastie's url 
  #   $ sake -P routes
  #   $ sake -P Rakefile db:remigrate
  elsif index = @args.index('-P')
    die Pastie.paste(examine(index))

  ##
  # Start a Mongrel handler which will serve local Rake tasks
  # to anyone who wants them.
  #
  # $ sake -S
  #
  # Set a port
  # $ sake -S -p 1111
  #
  # Daemonize
  # $ sake -S -d
  elsif @args.include? '-S'
    return serve_tasks

  ##
  # Prints Sake and Rake versions.
  elsif @args.include? '--version'
    version

  ##
  # Prints out the help screen.
  elsif @args.include? '-h' or @args.include? '--help'
    return Help.display
  end

  ##
  # Runs Rake proper, including our ~/.sake tasks.
  run_rake
end