Contributing To Rails By Plugin Gem

  • Published on
    08-May-2015

  • View
    1.465

  • Download
    0

Transcript

<ul><li>1.Contributing to Rails with plugins or gems Richard Huang E kohe www.ekohe.com Web Development &amp; Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development</li></ul> <p>2. Agenda </p> <ul><li>Testing </li></ul> <ul><li>Plugins </li></ul> <ul><li>Gems </li></ul> <ul><li>Contribute </li></ul> <p>www.ekohe.com Web Development &amp; Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development 3. Why use plugins or gems </p> <ul><li>Component </li></ul> <ul><li>Robust </li></ul> <ul><li>Multiple choices </li></ul> <p>www.ekohe.com Web Development &amp; Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development 4. Why write a plugin or gem </p> <ul><li>Share your ideas </li></ul> <ul><li>DRY </li></ul> <ul><li>Learn a lot </li></ul> <ul><li>Make your code better </li></ul> <p>www.ekohe.com Web Development &amp; Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development 5. Plugin www.ekohe.com Web Development &amp; Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development </p> <ul><li>Read the guides first </li></ul> <ul><li><ul><li>http://guides.rubyonrails.org/plugins.html </li></ul></li></ul> <ul><li>Read other peoples plugins </li></ul> <ul><li>Just do it </li></ul> <p>6. Plugin structure www.ekohe.com Web Development &amp; Graphic Design China 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 7. Plugin structure www.ekohe.com Web Development &amp; Graphic Design China 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 8. Testing the more, the better www.ekohe.com Web Development &amp; Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development </p> <ul><li>Tests are documents </li></ul> <ul><li>Tests make your code robust </li></ul> <ul><li>Test s e nable good communication between you and contributors </li></ul> <p>9. Autotest www.ekohe.com Web Development &amp; Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development </p> <ul><li>autotest </li></ul> <ul><li>a utospec </li></ul> <p>10. Testing ActiveRecord www.ekohe.com Web Development &amp; Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development </p> <ul><li>Use sqlite3 (memory) </li></ul> <ul><li>Create and drop table each time </li></ul> <ul><li>Silence your migration </li></ul> <p>11. Adding methods www.ekohe.com Web Development &amp; Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development </p> <ul><li>class methods and instance methods </li></ul> <p>12. Changing method behavior www.ekohe.com Web Development &amp; Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development </p> <ul><li>alias_method </li></ul> <p>13. Hack with different rails versions www.ekohe.com Web Development &amp; Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development </p> <ul><li>Implementations are different in different rails versions </li></ul> <p>14. Configure your plugin www.ekohe.com Web Development &amp; Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development </p> <ul><li>Enable or disable plugin </li></ul> <p>15. Lazy loading www.ekohe.com Web Development &amp; Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development </p> <ul><li>autoload </li></ul> <p>16. Reuse logic www.ekohe.com Web Development &amp; Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development </p> <ul><li>Similar to writing rails app </li></ul> <ul><li><ul><li>Model </li></ul></li></ul> <ul><li><ul><li>Controller </li></ul></li></ul> <ul><li><ul><li>Helper </li></ul></li></ul> <ul><li><ul><li>Task </li></ul></li></ul> <p>17. README www.ekohe.com Web Development &amp; Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development </p> <ul><li>Let others know what you are doing </li></ul> <ul><li>Rdoc, Textile or Markdown </li></ul> <ul><li>An example is better </li></ul> <p>18. Gem www.ekohe.com Web Development &amp; Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development </p> <ul><li>Easier to maintain </li></ul> <ul><li>Easier to upgrade </li></ul> <ul><li>Includes dependencies automatically </li></ul> <ul><li>Can use without rails </li></ul> <p>19. Gem tool -- Jeweler www.ekohe.com Web Development &amp; Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development </p> <ul><li>Defining your gem </li></ul> <ul><li>Bumping gem version </li></ul> <ul><li>Releasing gem </li></ul> <p>20. Adding gem rake www.ekohe.com Web Development &amp; Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development </p> <ul><li>Rails does not load gem rake </li></ul> <ul><li>Load it yourself </li></ul> <p>21. Adding executable to gem www.ekohe.com Web Development &amp; Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development </p> <ul><li>Using optparse to get input </li></ul> <ul><li>Defining executable in gemspec </li></ul> <p>22. Contribute www.ekohe.com Web Development &amp; Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development </p> <ul><li>Write down your ideas </li></ul> <ul><li>Share your codes (rubyforge, github, gemcutter, etc.) </li></ul> <ul><li>Tell others what you do </li></ul> <ul><li>Use it and improve it </li></ul> <p>23. Contribute www.ekohe.com Web Development &amp; Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development </p> <ul><li>Dont be afraid of reinventing the wheel </li></ul> <ul><li>Dont be afraid of ugly code </li></ul> <ul><li>Dont be afraid of bugs </li></ul> <p>24. To be a better contributor www.ekohe.com Web Development &amp; Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development </p> <ul><li>Read other peoples plugins </li></ul> <ul><li><ul><li>http://github.com/flyerhzm/monitor </li></ul></li></ul> <p>25. Q&amp;A Thank you Website: http://www.huangzhimin.com Github: http://github.com/flyerhzm www.ekohe.com Web Development &amp; Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development </p>

Recommended

View more >