Your SlideShare is downloading. ×
The Joy of Gems: Cooking up Rails Plugins
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

The Joy of Gems: Cooking up Rails Plugins

5,510
views

Published on

Published in: Technology, Education

1 Comment
2 Likes
Statistics
Notes
No Downloads
Views
Total Views
5,510
On Slideshare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
9
Comments
1
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Transcript

    • 1. The Joy ofGems:Cooking up http://www.flickr.com/photos/globetrotter1937/130805247
    • 2. As of Rails 3.2,vendor/plugins is http://www.flickr.com/photos/editor/172690560
    • 3. 1. No Versioning2. Encourages LocalModification
    • 4. 1. Fork on Github http://en.wikipedia.org/wiki/File:Acharia_stimulea_0795036.jpg
    • 5. 2. Create a gem$ bundle gem csv_import create csv_import/Gemfile conflict csv_import/RakefileOverwrite /Users/pm/github/csv_import/Rakefile? (enter"h" for help) [Ynaqdh] force csv_import/Rakefile create csv_import/.gitignore create csv_import/csv_import.gemspec conflict csv_import/lib/csv_import.rbOverwrite /Users/pm/github/csv_import/lib/csv_import.rb?(enter "h" for help) [Ynaqdh] n skip csv_import/lib/csv_import.rb create csv_import/lib/csv_import/version.rbInitializating git repo in /Users/pm/github/csv_import http://en.wikipedia.org/wiki/File:Monarch_Butterfly_Danaus_plexippus_Vertical_Caterpillar_2000px.jpg
    • 6. 3. Use Rails 3 Stylerequire railsmodule CsvImport class Engine < Rails::Engine endend http://en.wikipedia.org/wiki/File:CH_Caterpillar.jpg
    • 7. Rails::Railtie Rails::Engine Text Rails::ApplicationDoorkeeper::Application
    • 8. Rails::RailtieRailtie is the core of theRails framework andprovides several hooks toextend Rails and/ormodify the initializationprocess.
    • 9. Rails::Railtieclass MyRailtie < Rails::Railtie initializer "my_railtie.config" do |app| app.middleware.use MyRailtie::Middleware endend http://www.flickr.com/photos/stuckincustoms/211239773/
    • 10. Rails::EngineRails::Engine allows youshare functionality withother applications.Since Rails 3.0, everyRails::Application is justan engine. http://www.flickr.com/photos/stuckincustoms/1221214740/
    • 11. Rails::ApplicationRails::Application is anEngine with theresponsibility ofcoordinating the wholeboot process. http://www.flickr.com/photos/seangreenberg/2513414034
    • 12. 4. IntegrationActiveRecord::Base.configurations = {test => {adapter: sqlite3, database: :memory:}}ActiveRecord::Base.establish_connection(test)app = Class.new(Rails::Application)app.config.root = File.dirname(__FILE__)app.initialize!app.routes.draw { resources :members }Class.new(ActiveRecord::Migration) do def self.up create_table(:members) do |t| t.string :email; t.string :name end add_index :members, :email, :unique => true endend.up http://en.wikipedia.org/wiki/File:Baby_Caterpillars_crop2.jpg
    • 13. Capybara!feature "import csv" do scenario "with only utf-8" do visit members_path attach_file csv, fixtures/utf-8.csv click_button "Import" page.find("td:first").text.should == " " endend
    • 14. 4. Test withgem csv_builder, path: ~/csv_builder http://www.flickr.com/photos/vickisnature/6126452631
    • 15. 5. Release!$ rake -Trake build # Build csv_import-0.0.1.gem into the pkg directoryrake install # Build and install csv_import-0.0.1.gem into system gemsrake release # Create tag v0.0.1 and build and push csv_import-0.0.1.gem to Rubygems http://www.flickr.com/photos/spettacolopuro/3906679719/
    • 16. 6. Update Gemfile gem csv_builderhttp://www.flickr.com/photos/amaynez/3355325172
    • 17. 7. Pull Request http://en.wikipedia.org/wiki/File:Charaxes_brutus_natalensis.jpg
    • 18. Thanks!Paul http://www.flickr.com/photos/axlefoley/3825217644/ @pwi

    ×