Wrake
A web partner of Rake. Runs wrake via web api.
But why?
When you run rake inside rails, you have to load the entire application. By running wrake, rake will be callled via web API, through your aready loaded rails app.
Instalation
Add this line to your application's Gemfile:
gem 'wrake'
And then execute:
$ bundle
$ rails g wrake:install
This will create the following files:
-
config/wrake.yml
- the configuration file is self explicative. -
config/initializers/wrake.rb
- the configuration file is self explicative.
Also, you wil need to mount the engine:
# config/routes.rb
mount Wrake::Engine, at: 'wrake'
Usage
Using API
api = Wrake::Api.new(url: base_url, username: username, password: password)
# or to get the api with default configuration
api = Wrake.api
response = api.invoke_task('some:task', { args: 'a b c' })
# or
response = api.invoke_task('some:task', args: ['a', 'b', 'c'])
puts response.code, response.headers, response.body, response.message
Using the CLI
wrake cache:clean -c path/to/wrake.yml -e development
wrake mail:welcome new@user.com -c path/to/wrake.yml
Password protecting the API
By default, the API is protected by Basic Auth. You could change the default behavior by overwriting the wrake_authorization method:
class ApplicationController < ActionController::Base
def wrake_authorization
authenticate_or_request_with_http_basic do |username, password|
User.with_wrake_privileges.where(email: username, password: password).first!
end
end
end
TODO
Authors
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
** Do not forget to write tests**