Created
July 11, 2019 23:56
-
-
Save flynn1982/cab5dff976d413db7c8262fb5bdef92f to your computer and use it in GitHub Desktop.
Rails Custom Generator and Thor Example
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
class CoolFileGenerator < Rails::Generators::Base | |
def set_file_name | |
@file_name = "cool_file.rb" | |
end | |
def create_cool_file | |
body = ask "What should I write into the file?" | |
create_file @file_name, "Insert after me \n" + body | |
end | |
def add_more_coolness | |
insert_into_file @file_name, after: "Insert after me \n" do | |
content = ask "What more should I write into the file?" | |
content + "\n" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment