Created
November 22, 2020 12:41
-
-
Save shanenoi/225313aeb8bdcd309cd1350d52475792 to your computer and use it in GitHub Desktop.
Series Learning Ruby
This file contains 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
def get_namespace(url) | |
namespace = "" | |
url.length.times { |i| | |
position = url.length - i - 6 | |
if url[position] == "/" | |
break | |
end | |
namespace = url[position] + namespace | |
} | |
return namespace | |
end | |
def get_tasks(content) | |
matches = content.scan(/([^ ]+): :environment/) | |
for task in matches | |
yield task[0] | |
end | |
end | |
def main | |
command_content = IO.popen("find . -type f | grep -P '\\.rake$'") | |
for rake_file in command_content.readlines | |
rake_file[-1] = '' | |
namespace = get_namespace(rake_file) | |
get_tasks(File.read(rake_file)) { |task| | |
system("rake #{namespace}:#{task}") | |
} | |
end | |
end | |
if __FILE__ == $0 | |
main | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instead of searching and running all tasks manually. This code will help you!