Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 332
Maxim Abramchuk Avatar asked Oct 19 '22 18:10

Maxim Abramchuk


1 Answers

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

like image 87
Maxim Abramchuk Avatar answered Oct 27 '22 18:10

Maxim Abramchuk