Wrake

A web partner of Rake. Runs wrake via web api.

Build Status Coverage Status Code Climate Dependency Status Gem Version

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 [email protected] -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

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

** Do not forget to write tests**