Upload
daniel-lv
View
1.472
Download
0
Embed Size (px)
Citation preview
Contributing to Rails
with plugins or gems
Richard Huang
Ekohe
www.ekohe.comWeb Development & Graphic DesignChina Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
AgendaTesting
Plugins
Gems
Contribute
www.ekohe.comWeb Development & Graphic DesignChina Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Why use plugins or gemsComponent
Robust
Multiple choices
www.ekohe.comWeb Development & Graphic DesignChina Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Why write a plugin or gemShare your ideas
DRY
Learn a lot
Make your code better
www.ekohe.comWeb Development & Graphic DesignChina Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Plugin
www.ekohe.comWeb Development & Graphic DesignChina Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Read the guides first
http://guides.rubyonrails.org/plugins.html
Read other people’s plugins
Just do it
Plugin structure
www.ekohe.comWeb Development & Graphic DesignChina Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Executed when plugin loaded
Executed when plugin installed
Executed when plugin destroyed
Rake task added to rails rake load path
Logic codes of your plugin
Test codes of your plugin
Define plugin rake tasks
Plugin structure
www.ekohe.comWeb Development & Graphic DesignChina Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Plugin logic codes
Textile README
require ‘bullet’
require ‘bulletware’reqire
‘bullet/association’……
Rspec to test plugins
Testing – the more, the better
www.ekohe.comWeb Development & Graphic DesignChina Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Tests are documents
Tests make your code robust
Tests enable good communication between you and contributors
Autotest
www.ekohe.comWeb Development & Graphic DesignChina Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
autotest
autospec
Testing ActiveRecord
www.ekohe.comWeb Development & Graphic DesignChina Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Use sqlite3 (memory)
Create and drop table each time
Silence your migration
Adding methods
www.ekohe.comWeb Development & Graphic DesignChina Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
class methods and instance methods
Changing method behavior
www.ekohe.comWeb Development & Graphic DesignChina Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
alias_method
Hack with different rails versions
www.ekohe.comWeb Development & Graphic DesignChina Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Implementations are different in different rails versions
Configure your plugin
www.ekohe.comWeb Development & Graphic DesignChina Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Enable or disable plugin
Lazy loading
www.ekohe.comWeb Development & Graphic DesignChina Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
autoload
Reuse logic
www.ekohe.comWeb Development & Graphic DesignChina Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Similar to writing rails app
–Model
–Controller
–Helper
–Task
README
www.ekohe.comWeb Development & Graphic DesignChina Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Let others know what you are doing
Rdoc, Textile or Markdown
An example is better
Gem
www.ekohe.comWeb Development & Graphic DesignChina Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Easier to maintain
Easier to upgrade
Includes dependencies automatically
Can use without rails
Gem tool -- Jeweler
www.ekohe.comWeb Development & Graphic DesignChina Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Defining your gem
Bumping gem version
Releasing gem
Adding gem rake
www.ekohe.comWeb Development & Graphic DesignChina Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Rails does not load gem rake
Load it yourself
Adding executable to gem
www.ekohe.comWeb Development & Graphic DesignChina Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Using optparse to get input
Defining executable in gemspec
Contribute
www.ekohe.comWeb Development & Graphic DesignChina Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Write down your ideas
Share your codes (rubyforge, github, gemcutter, etc.)
Tell others what you do
Use it and improve it
Contribute
www.ekohe.comWeb Development & Graphic DesignChina Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Don’t be afraid of reinventing the wheel
Don’t be afraid of ugly code
Don’t be afraid of bugs
To be a better contributor
www.ekohe.comWeb Development & Graphic DesignChina Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Read other people’s plugins
http://github.com/flyerhzm/monitor
Q&A
Thank you
Website: http://www.huangzhimin.com
Github: http://github.com/flyerhzm
www.ekohe.comWeb Development & Graphic DesignChina Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development