1 / 19

Gems and engines

Gems and engines. Plan. Creating Gems Structure of a gem Testing Extending Classes Providing Rails models/controllers Releasing Hosting your own gems. A few examples. Admin engine Auditing engine Authentication engine Accounting engine (not actually an engine) Custom OmniAuth module

magnar
Download Presentation

Gems and engines

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. Gems and engines

  2. Plan Creating Gems Structure of a gem Testing Extending Classes Providing Rails models/controllers Releasing Hosting your own gems

  3. A few examples Admin engine Auditing engine Authentication engine Accounting engine (not actually an engine) Custom OmniAuth module Core models engine • Dev’ Gem • Settings engine • Support gem - a bit like ActiveSupport • Application theme gems (using asset pipeline) • UI framework for building reusable widgets • Fudge CI build tool

  4. Creating gems Bundler: bundle gem my_gem Rails: rails plugin new [--mountable] [-T --dummy-path=spec/dummy --skip-bundle]

  5. Structure of a gem

  6. Example .gemspec

  7. Gemspec or gemfile?!?! Your Gemfile should look like this... • Always use the .gemspec for dependencies • Only touch the Gemfile if you must do (e.g. Github) • Be explicit about dependency versions • http://yehudakatz.com/2010/12/16/clarifying-the-roles-of-the-gemspec-and-gemfile/

  8. Autoloading my_gem.rb: my_gem/extensions.rb: my_gem/extensions/extension_a.rb:

  9. Or... Lots of Require’s

  10. Testing gems Regular Gems: Just add ‘rspec’ as a dependency Rails Engines http://whilefalse.net/2012/01/25/testing-rails-engines-rspec/

  11. Testing gems Rails is sloooooooow...... Test public API of classes Don’t test private methods TDD is awesome - you should do it Continuous Integration - Use Fudge (I’ve heard it’s awesome...) http://github.com/Sage/fudge

  12. Extending classes Separate into modules CoreClass.send(:include, MyExtensionModule) ActiveSupport.on_load Writing a class macro

  13. Separate into modules

  14. send(:include...

  15. Class macros

  16. Providing Rails modls/controllers etc. Use a Rails Engine Engines can be mounted: Views can be overridden

  17. Releasing gems Building - rake build Install locally - rake install Tag and push to RubyGems - rake release

  18. Deploying gems (advanced) Run your own gem/doc server - gem server Create an index - gem generate_index -d /some/place Use a custom gem server in a Gemfile source ‘http://my.gem.server.com’

  19. THE END

More Related