190 likes | 366 Views
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
E N D
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 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
Creating gems Bundler: bundle gem my_gem Rails: rails plugin new [--mountable] [-T --dummy-path=spec/dummy --skip-bundle]
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/
Autoloading my_gem.rb: my_gem/extensions.rb: my_gem/extensions/extension_a.rb:
Or... Lots of Require’s
Testing gems Regular Gems: Just add ‘rspec’ as a dependency Rails Engines http://whilefalse.net/2012/01/25/testing-rails-engines-rspec/
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
Extending classes Separate into modules CoreClass.send(:include, MyExtensionModule) ActiveSupport.on_load Writing a class macro
Providing Rails modls/controllers etc. Use a Rails Engine Engines can be mounted: Views can be overridden
Releasing gems Building - rake build Install locally - rake install Tag and push to RubyGems - rake release
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’