Ответ 1
На самом деле я могу представить три способа передачи аргументов между задачами Rake.
-
Используйте встроенную поддержку Rakes для аргументов:
# accepts argument :one and depends on the :second task. task :first, [:one] => :second do |t, args| puts args.inspect # => '{ :one => "one" }' end # argument :one was automagically passed from task :first. task :second, :one do |t, args| puts args.inspect # => '{ :one => "one" }' end $ rake first[one]
-
Непосредственно вызывать задачи через
Rake::Task#invoke
:# accepts arguments :one, :two and passes them to the :second task. task :first, :one, :two do |t, args| puts args.inspect # => '{ :one => "1", :two => "2" }' task(:second).invoke(args[:one], args[:two]) end # accepts arguments :third, :fourth which got passed via #invoke. # notice that arguments are passed by position rather than name. task :second, :third, :fourth do |t, args| puts args.inspect # => '{ :third => "1", :fourth => "2" }' end $ rake first[1, 2]
-
Еще одно решение - это основной объект приложения обезьяны Rakes Rake:: Application
и использовать его для хранения условных значений:class Rake::Application attr_accessor :my_data end task :first => :second do puts Rake.application.my_data # => "second" end task :second => :third do puts Rake.application.my_data # => "third" Rake.application.my_data = "second" end task :third do Rake.application.my_data = "third" end $ rake first