Created
December 4, 2018 05:01
-
-
Save TSMMark/77cc739a785f4461364ca4a0fb2a09fb to your computer and use it in GitHub Desktop.
Load rakefile once only
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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