staying dry in rails using code generation
DESCRIPTION
A presentation about a code generator that generates a complete datamodel for ruby on railsTRANSCRIPT
![Page 1: Staying Dry in Rails using code generation](https://reader033.vdocuments.us/reader033/viewer/2022052906/558deece1a28ab2b7e8b465a/html5/thumbnails/1.jpg)
Being DRYYour code might be,
but are you?
By Jeroen van Dijk
![Page 2: Staying Dry in Rails using code generation](https://reader033.vdocuments.us/reader033/viewer/2022052906/558deece1a28ab2b7e8b465a/html5/thumbnails/2.jpg)
Examples of tools to make you DRY...
rails-templates capistrano
I18n rake scaffolds sass
haml make_resourceful
![Page 3: Staying Dry in Rails using code generation](https://reader033.vdocuments.us/reader033/viewer/2022052906/558deece1a28ab2b7e8b465a/html5/thumbnails/3.jpg)
What is missing to keep you DRY?. . . An idea:Scaffold of your complete datamodel?
![Page 4: Staying Dry in Rails using code generation](https://reader033.vdocuments.us/reader033/viewer/2022052906/558deece1a28ab2b7e8b465a/html5/thumbnails/4.jpg)
But scaffolds generate code...... for just one resource!... not following my own conventions!... that still requires a lot of customization!
All true, that’s why I’ll not talk about the old way of scaffolding...
![Page 5: Staying Dry in Rails using code generation](https://reader033.vdocuments.us/reader033/viewer/2022052906/558deece1a28ab2b7e8b465a/html5/thumbnails/5.jpg)
Instant Railsrails shop -m http://www.jeevidee.nl/instant_rails_application.txt
![Page 6: Staying Dry in Rails using code generation](https://reader033.vdocuments.us/reader033/viewer/2022052906/558deece1a28ab2b7e8b465a/html5/thumbnails/6.jpg)
Don’t like uml or need customization?
For examples or just to startFor an old application: “rake dm:export”For a new application: “rake dm:xmi:to_yaml”
Customize• which templates should be generated• which attributes/association should be used in your templates
![Page 7: Staying Dry in Rails using code generation](https://reader033.vdocuments.us/reader033/viewer/2022052906/558deece1a28ab2b7e8b465a/html5/thumbnails/7.jpg)
Not enough?• Adapt the templates to your liking• Define your own formats
email: native_type: string examples: valid: [email protected] invalid: jeroen_jeevidee.nl display: default: “mail_to(“{{field}}”)
![Page 8: Staying Dry in Rails using code generation](https://reader033.vdocuments.us/reader033/viewer/2022052906/558deece1a28ab2b7e8b465a/html5/thumbnails/8.jpg)
Useful for...• super fast prototyping • refactoring • applying good conventions (e.g. css, models)
Not just uml2rails
![Page 9: Staying Dry in Rails using code generation](https://reader033.vdocuments.us/reader033/viewer/2022052906/558deece1a28ab2b7e8b465a/html5/thumbnails/9.jpg)
The new DRY for Rails?• Design the basics of your application• Run the generator with your own customizations• Customize the application
![Page 10: Staying Dry in Rails using code generation](https://reader033.vdocuments.us/reader033/viewer/2022052906/558deece1a28ab2b7e8b465a/html5/thumbnails/10.jpg)
Summary of featuresYaml/Uml export to: OK Models OK Views (+helpers) OK Controllers OK Migrations OK Fixtures OK Custom formats FAIL Documentation + Tests PENDING Intelligent generation of Routes PENDING Generation of Tests/Specs/Stories
Information on attributes and associations is exploited in all of the above.
![Page 11: Staying Dry in Rails using code generation](https://reader033.vdocuments.us/reader033/viewer/2022052906/558deece1a28ab2b7e8b465a/html5/thumbnails/11.jpg)
More info or contributeSourcehttp://github.com/jeroenvandijk/dm_generatorhttp://github.com/jeroenvandijk/dm_templateshttp://github.com/jeroenvandijk/dm_designs
Documentation/blog (coming soon)http://www.jeevidee.nl
Demonstrationrails shop -m http://www.jeevidee.nl/instant_rails_application.txt
![Page 12: Staying Dry in Rails using code generation](https://reader033.vdocuments.us/reader033/viewer/2022052906/558deece1a28ab2b7e8b465a/html5/thumbnails/12.jpg)
Questions?