Maxim Abramchuk
Maxim Abramchuk

Reputation: 245

Load rake tasks from ruby gem

I'm writing a gem and I want to have an access to the gem rake tasks from my rails app. To do this I use Railties.

I have lib/frontrockets-rails/railtie.rb with

require 'frontrockets-rails'
require 'rails'

module FrontrocketsRails
  class Railtie < Rails::Railtie
    railtie_name :frontrockets

    rake_tasks do
      load 'tasks/frontrockets.rake'
    end
  end  
end

and

lib/frontrockets-rails.rb with

module FrontrocketsRails
  require 'frontrockets-rails/railtie' if defined?(Rails)
end

and of course lib/tasks/frontrockets.rake

namespace :frontrockets do
  desc 'Create .bowerrc file'
  task :create_bowerrc do
    touch '.bowerrc'
  end

  task :install => [:create_bowerrc] do
  end
end

But when I install this gem in my Rails app I still can't execute this rake tasks, there are no them in the rake -T list.

Upvotes: 5

Views: 1955

Answers (1)

Maxim Abramchuk
Maxim Abramchuk

Reputation: 245

I've just restarted spring and new rake tasks appeared in my rake -T list. :)

Upvotes: 3

Related Questions