bringing the thunder with thor rails generators for the command line n.
Skip this Video
Loading SlideShow in 5 Seconds..
Bringing the Thunder with Thor & Rails Generators for the Command Line PowerPoint Presentation
Download Presentation
Bringing the Thunder with Thor & Rails Generators for the Command Line

Loading in 2 Seconds...

  share
play fullscreen
1 / 26
Download Presentation

Bringing the Thunder with Thor & Rails Generators for the Command Line - PowerPoint PPT Presentation

altessa
187 Views
Download Presentation

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

- - - - - - - - - - - - - - - - - - - - - - - - - - - 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?