Rails Plugins rolling your own
Carlisia Campos
why plugins in Rails?
Rails is infrastructure only
what goes into an infrastructure?
David Heinemeier Hansson’s Two Tests: • “Is this something that’s useful by the many?” AND • “Is this infrastructure or business logic?”
two things are clear
• Business specific logic does not belong in core Rails • But we need more
the options
• Use a plugin that does exactly what you want • Modify an existing plugin • Roll your own
in any case
“Never use a plugin you would not be able to write yourself.”
—Jamis Buck (http://weblog.jamisbuck.org/2007/2/21/ review-build-your-own-ruby-on-rails-web-applications)
what does that quote mean to you?
but wait, plugins are dead
LONG LIVE THE GEM
• Ruby 1.9 includes the gem command with every installation • Has versioning, is a better packaging system • SCM agnostic • More easily accessible outside of Rails
guts of a gem
• .gem file: archives, like a zip file. Contains all files a gem uses, lib/ and test/ directories, structure is up to developer • readme file (description, license info) • metadata (name of developer, website) • some of these come from the GemSpec
soul of a gem
GemSpec • Specifies information about the gem • Name, version number, list of files, metadata, and more • GemSpec Reference on rubygems.org
alternative conceptions
hoe • Hoe on rubyfore.org • automates gem packaging • but includes dependencies in all gems it produces
echoe • echoe on rubyforge.org • automates gem packaging • does not include dependencies in all gems it produces like hoe • but it doesn’t keep up with hoe
a gem’s existence
Distribution Options • http or ftp download (simplest) • via your own gem server • adding a gem to RubyForge (the default repository) • on a local network via RubyGem’s built-in web server
learn more online
• Dr. Nic’s NewGem • Tutorial: Publishing RubyGems with Hoe • The RubyGems bookshelf
references
• PeepCode Plugin Patterns • Online discussion: Why engines and components are not evil but distracting • Apress Practical Ruby Gems
thank you