1

I am making a rails generator, and instead of passing a filename as an argument, I would like it to open in a terminal editor, and once I save a file, read that file and continue.

This is similar to how git commit works. When I do git commit, it opens a file, I save, and it continues, but I'm not sure how I can go about doing the same thing in ruby. Any insight would be appreciated.

1 Answer 1

1

Figured it out.

def tmp_path
  t = Time.now.utc.strftime '%Y%m%d%H%M%S'
  "/tmp/#{t}_generator_crud_#{_namespace '_'}#{_table_name}_table"
end

path     = tmp_path
path     = Rails.root.join('lib','generators','templates','config.erb.yml').to_s
template = Erubis::Eruby.new File.read(path)
content  = template.result namespace:  _namespace,
                           table_name: _table_name
File.open(path, 'w'){|f|f.write content}
system 'vi', path
config = YAML.load_file path
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.