Last active
August 29, 2015 14:05
-
-
Save Widdershin/e621669335ae2503a204 to your computer and use it in GitHub Desktop.
A simple utility for creating Ruby/Rails app and spec code with one command.
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
#!/usr/bin/env python | |
""" | |
mkrb.py | |
Usage: | |
mkrb.py path_to_file | |
Example: | |
mkrb services/widget_extractor | |
Would create app/services/widget_extractor.rb and | |
spec/services/widget_extractor_spec.rb with stub contents. | |
""" | |
import os | |
import sys | |
APP_CONTENTS = "class {classname}\nend\n".format | |
SPEC_CONTENTS = "require 'rails_helper'\n\ndescribe {classname} do\nend\n".format | |
def main(full_path): | |
classname = os.path.basename(full_path).title().replace('_', '') | |
create_app_file(full_path, classname) | |
create_spec_file(full_path, classname) | |
def create_app_file(path, classname): | |
app_path = "app/{path}.rb".format(path=path) | |
with open(app_path, 'w') as app_file: | |
app_file.write(APP_CONTENTS(classname=classname)) | |
def create_spec_file(path, classname): | |
spec_path = "spec/{path}_spec.rb".format(path=path) | |
with open(spec_path, 'w') as spec_file: | |
spec_file.write(SPEC_CONTENTS(classname=classname)) | |
if __name__ == "__main__": | |
main(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment