Your SlideShare is downloading. ×
0
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
Plug it on!... with railties
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

Plug it on!... with railties

1,157

Published on

Slides for the MagmaRails conference @ colima, october 15th

Slides for the MagmaRails conference @ colima, october 15th

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,157
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
13
Comments
0
Likes
1
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













































  • Transcript

    • 1. Plug it on!... with Railties
    • 2. Edgar J. Suárez ['twitter.com','github.com', 'rails.mx'].each do |host|   link_to "#{host}/edgarjs" end mail_to "edgar.js@gmail.com"
    • 3. Rail-tie Rail (HDR) @ sadi-junior / flickr.com
    • 4. .init! Endeavour launch @ msimdottv / flickr.com
    • 5. rails server
    • 6. script/server require ‘config/application’ require ‘config/boot’
    • 7. config/boot.rb Bundler.setup
    • 8. config/application.rb require ‘rails/all’
    • 9. rails/all.rb require ‘rails’
    • 10. rails.rb require ‘pathname’ require ‘active_support’ ... require ‘rails/application’ ...
    • 11. rails/application.rb require ‘rails/railties_path’ require ‘rails/plugin’ require ‘rails/engine’
    • 12. rails/engine.rb require ‘rails/railtie’
    • 13. rails/railtie.rb require ‘rails/initializable’ require ‘rails/configuration’
    • 14. rails/configuration.rb require ‘rails/paths’ require ‘rails/rack’
    • 15. rails/all.rb require 'rails' %w( active_record  action_controller  action_mailer   active_resource   rails/test_unit ).each do |framework|   begin     require "#{framework}/railtie"   rescue LoadError   end end
    • 16. rails new your_app -O config/application.rb require 'rails/all'
    • 17. rails new your_app -O config/application.rb require 'rails' # require 'active_record/railtie' require 'action_controller/railtie' require 'action_mailer/railtie' require 'active_resource/railtie' require 'rails/test_unit/railtie'
    • 18. Modular origami : the collection so far @ fdecomite / flickr.com
    • 19. Lego Trains @ psd / flickr.com
    • 20. Railtie + Engine + Application + Plugin = MODULAR RAILS
    • 21. Railtie
    • 22. Railtie Initializers Configuration Rake tasks Generators
    • 23. Initializers initializer "my_railtie.initialize" do |app|   app.middleware.use MyRailtie::Middleware end
    • 24. Configuration config.generators.orm :my_railtie_orm # Add a to_prepare block which is executed once in production # and before which request in development config.to_prepare do   MyRailtie.setup! end
    • 25. Rake tasks rake_tasks do   load "path/to/my_railtie.tasks" end
    • 26. Generators generators do   require "path/to/my_railtie_generator" end
    • 27. Engine < Railtie Initializers Configuration Paths Rake tasks Generators
    • 28. Paths paths.app                 = "app" paths.app.controllers     = "app/controllers" paths.app.helpers         = "app/helpers" paths.app.models          = "app/models" paths.app.views           = "app/views" paths.lib                 = "lib" paths.lib.tasks           = "lib/tasks" paths.config              = "config" paths.config.initializers = "config/initializers" paths.config.locales      = "config/locales" paths.config.routes       = "config/routes.rb"
    • 29. Application < Engine Initializers Configuration Holds routes Rake tasks Builds middleware stack Generators Paths
    • 30. config/application.rb module YourRailsApp class Application < Rails::Application   end end
    • 31. Plugin < Engine
    • 32. Plugin To be continued... It's so damn Sexy @ picsaremine / flickr.com
    • 33. .init! Endeavour launch @ msimdottv / flickr.com
    • 34. config/environment.rb YourApp::Application.initialize!
    • 35. YourApp::Application.initialize! initializers.each do |initializer|   initializer.run(*args) end def initializers railties.all { |r| initializers += r.initializers } end def all(&block)   @all ||= railties + engines + plugins   @all.each(&block) if block   @all end
    • 36. railties + engines + plugins def railties   @railties ||= ::Rails::Railtie.subclasses.map(&:new) end def engines   @engines ||= ::Rails::Engine.subclasses.map(&:new) end def plugins  @plugins ||= begin     plugin_names = (@config.plugins || [:all]).map { |p| p.to_sym }     Plugin.all(plugin_names, @config.paths.vendor.plugins)   end end
    • 37. Plugin.all def self.all(list, paths)   plugins = []   paths.each do |path|     Dir["#{path}/*"].each do |plugin_path|       plugin = new(plugin_path)       next unless list.include?(plugin.name) || list.include?(:all)       plugins << plugin     end   end   plugins.sort_by do |p|     [list.index(p.name) || list.index(:all), p.name.to_s]   end end
    • 38. Plugin.new def initialize(root)   @name = File.basename(root).to_sym   config.root = root end initializer :load_init_rb, :before => :load_application_initializers do |app|   file   = Dir["#{root}/{rails/init,init}.rb"].first   config = app.config   eval(File.read(file), binding, file) if file && File.file?(file) end
    • 39. How to make your Railtie
    • 40. # railtie_name/lib/railtie_name/railtie.rb require 'rails' module RailtieName   class Railtie < Rails::Railtie     config.some_config = true     initializer "railtie_name.initializating" do |app|       # your initialization here     end   end end
    • 41. require 'railtie_name/railtie'
    • 42. Demo
    • 43. Thanks! http://twitter.com/edgarjs http://github.com/edgarjs http://rails.mx/edgarjs http://freshout.us edgar.js@gmail.com

    ×