Skip to content

Instantly share code, notes, and snippets.

@TSMMark
Created December 4, 2018 05:01
Show Gist options
  • Save TSMMark/77cc739a785f4461364ca4a0fb2a09fb to your computer and use it in GitHub Desktop.
Save TSMMark/77cc739a785f4461364ca4a0fb2a09fb to your computer and use it in GitHub Desktop.
Load rakefile once only
module RakeUtils
class << self
# Load the rakefile, unless it's already been loaded.
def load_rakefile
@load_rakefile ||= begin
load "#{PROJECT_ROOT_PATH}/Rakefile"
true
end
end
# Execute a rake task.
#
# @param task_name [String] the complete name of the task including namespace.
#
# @param args [Hash] the arguments to be passed in for the task
#
# @example
# run_task("db:whatever", :foo => "bar")
def run_task(task_name, args = nil)
Rake.application[task_name].execute(args && args.map { |k, v| v.nil? ? nil : [k.to_sym, v.to_s] }.compact.to_h)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment