Gems and engines
This presentation is the property of its rightful owner.
Sponsored Links
1 / 19

Gems and engines PowerPoint PPT Presentation


  • 116 Views
  • Uploaded on
  • Presentation posted in: General

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

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Gems and engines

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

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

Creating gems

Bundler:

bundle gem my_gem

Rails:

rails plugin new [--mountable] [-T --dummy-path=spec/dummy --skip-bundle]


Structure of a gem

Structure of a gem


Example gemspec

Example .gemspec


Gemspec or gemfile

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

Autoloading

my_gem.rb:

my_gem/extensions.rb:

my_gem/extensions/extension_a.rb:


Gems and engines

Or...

Lots of Require’s


Testing gems

Testing gems

Regular Gems:

Just add ‘rspec’ as a dependency

Rails Engines

http://whilefalse.net/2012/01/25/testing-rails-engines-rspec/


Testing gems1

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

Extending classes

Separate into modules

CoreClass.send(:include, MyExtensionModule)

ActiveSupport.on_load

Writing a class macro


Separate into modules

Separate into modules


Send include

send(:include...


Class macros

Class macros


Providing rails modls controllers etc

Providing Rails modls/controllers etc.

Use a Rails Engine

Engines can be mounted:

Views can be overridden


Releasing gems

Releasing gems

Building - rake build

Install locally - rake install

Tag and push to RubyGems - rake release


Deploying gems advanced

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’


The end

THE END


  • Login