1 / 26

Bringing the Thunder with Thor & Rails Generators for the Command Line

Bringing the Thunder with Thor & Rails Generators for the Command Line. *Boom*. Actual Summary. Thor (the ruby framework) Rails Generators Application Templates. What is Thor?. *In practice, not so much. Why Thor?. You need a CLI options parser It’s already installed (Rails 3)

altessa
Download Presentation

Bringing the Thunder with Thor & Rails Generators for the Command Line

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Bringing the Thunder with Thor & Rails Generators for the Command Line *Boom*

  2. Actual Summary • Thor (the ruby framework) • Rails Generators • Application Templates

  3. What is Thor? *In practice, not so much.

  4. Why Thor? • You need a CLI options parser • It’s already installed (Rails 3) • Useful file and directory operations • Creating a generator

  5. Flavors of Code Gen ~/projects/myproject(master)$ rails g model Product name:string ~/projects$ rails new myproject -m stock_project.rb ~/projects/myproject(master)$ petstore upgrade

  6. Key Resources • Thor::Actions - http://rdoc.info/github/wycats/thor/master/Thor/Actions.html • Rails::Generators - http://api.rubyonrails.org/classes/Rails/Generators/Actions.html • Writing/Overriding Generators - http://guides.rubyonrails.org/generators.html

  7. Using Generators rails generate model Turtle name:string

  8. Rolling your own rails g generator product

  9. Product Generator

  10. Templates

  11. Key Points • All public methods are invoked in order of declaration • Private methods are available in the template • Can have inline or external templates • ‘working’ directory is always the root of the project

  12. Thor::Actions

  13. Rails::Generators::Actions

  14. Stupid Generator Tricks

  15. Thor CLI Apps • Generating code can be done without a generator rails new MY_APP • Packaging as gem executable • Don’t need to clutter list of generators in projects • Example: A tool to upgrade to Rails 3

  16. Making a Gem http://asciicasts.com/episodes/245-new-gem-with-bundler

  17. Gemfile & gemspec

  18. Hello World

  19. Showing off

  20. Multiple Commands

  21. Running Thor Commands

  22. Application Templates • Just a .rb file with thor/rails generator commands • Used to configure new rails projects • Can be local or remote

  23. Sample Template

  24. Easier kickstarting

  25. Questions?

More Related