Search code examples
rubyrubygemsrakebundler

What is the path to load a rake task for a new gem


I try to create a new rubygem with bundler and intent to load the rake task from rubygem folder ~/work/bezier/lib/task/. But the pwd seems to be in the /Users/wizztjh/work/bezier_server, what is the path to load a rake task for a new gem?

my rubygem folder

bezier/lib
  /railtie.rb
  /task/get_transitions.rake

pry

From: /Users/wizztjh/work/bezier/lib/bezier/railtie.rb @ line 4 :

    1: module Bezier
    2:   class Railtie < Rails::Railtie
    3:     rake_tasks do
 => 4:       binding.pry
    5:       load "lib/task/get_transitions.rake"
    6:     end
    7:   end
    8: end

[1] pry(#<Bezier::Railtie>)> Dir.pwd
=> "/Users/wizztjh/work/bezier_server"
[2] pry(#<Bezier::Railtie>)> 

Because according to rubygem documentation

rake_tasks do
    load "path/to/my_railtie.tasks"
end

but what is path/to?


Solution

  • I try to use advance code search by github to search for Rails::Railtie rake_tasks do load broadcast and I found the solution.

    bezier/tasks/get_transitions.rake

    #bezier/lib/railtie.rb
    module Bezier
      class Railtie < Rails::Railtie
        railtie_name :bezier
        rake_tasks do 
           load "bezier/tasks/get_transitions.rake"
        end
      end
    end
    

    So, ruby gem railtie load pwd is the root of Gem.path