Skip to content

Instantly share code, notes, and snippets.

@shanenoi
Created November 22, 2020 12:41
Show Gist options
  • Save shanenoi/225313aeb8bdcd309cd1350d52475792 to your computer and use it in GitHub Desktop.
Save shanenoi/225313aeb8bdcd309cd1350d52475792 to your computer and use it in GitHub Desktop.
Series Learning Ruby
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
@shanenoi
Copy link
Author

Instead of searching and running all tasks manually. This code will help you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment