railties

22
If you like go a bit more in depth, please read Piotr Sarnacki article: http://piotrsarnacki.com/2010/06/18/rails-internals-railties/ Anyhow, here is my slides for meetup.

Upload: skills-matter

Post on 18-May-2015

2.264 views

Category:

Technology


0 download

DESCRIPTION

Recently I have been porting an app into Rails 3 and probably you have also been poking this new Rails 3 with ruby 1.9.2. Therefore I would like to discuss a bit more about Rails 3 itself. Particularly, things under railties lib directory covering classes such as Railtie, Engine, Application and will go through initialization with initializers. Along the way I'll show some examples how you can use this knowledge in your own gem or plugin. Nothing too fancy but should be useful for developing your next Rails

TRANSCRIPT

Page 1: Railties

If you like go a bit more in depth, please read Piotr Sarnacki article:

http://piotrsarnacki.com/2010/06/18/rails-internals-railties/

Anyhow, here is my slides for meetup.

Page 2: Railties

Poke into Rails 3 railites

Priit [email protected]

London13.09.2010

Page 3: Railties

puts 'Hello!'

Early days...Not so early days...

Recent days......or just short shameless self presentation.

Page 4: Railties

Presentation is about:

Railtie and it's responsibiltyEngine and Application classes

Initialization

...and one more thing ;-)

Page 5: Railties

Credits and thanks goes to:

Rails 3 source codeRails 3 edge guides

José Valim and other Devise developersPiotr Sarnacki and his summer work/blog

http://piotrsarnacki.comOwn experience during summer in Barcelona

Page 6: Railties

What's the responsibility of Railites:

Glues all togetherHandles all bootstrapping process

Provides rails command line interfaceProvides rails generators core

Page 7: Railties

What about class Railtie?railties/lib/rails/railtie.rb

Class Railtie is the core of the Rails Framework and provides several hooks to extend Rails and/or

modify the initialization process.

Page 8: Railties

Creating your own Railtie

# APP/Gemfilegem 'my_gem'

# GEM/lib/my_gem.rbrequrie 'my_gem/railtie' if defined?(Rails)

# GEM/lib/my_gem/railtie.rbmodule MyGem class Railtie < Rails::Railtie endend

Page 9: Railties

What about Engine class?

First, don't get confused with Engine plugin.Rails 3 Engine class is quite different thing.

Page 10: Railties

Engine is just subclass of Railtie

# railties/lib/rails/engine.rbmodule Rails class Engine < Railtie endend

Page 11: Railties

Available paths in an Engine

class MyEngine < Rails::Engine 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" end

Page 12: Railties

Use middleware in initialization

# lib/my_gem/railtie.rb class MyRailtie < Rails::Railtie initializer "my_railtie.initialization" do |app| app.middleware.use MyRailtie::Middleware endend

Page 13: Railties

One more thing :-)

Page 14: Railties

What to expect from Rails 3.1?

Page 15: Railties

What, not excited?

Page 16: Railties

Anyhow, heavy lifting done by Piotr Sarnacki in his time with Ruby Summer of Code.

At the moment treat his work as any other Rails edge code, I'm sure he welcomes any feedback.

Page 17: Railties

What to expect from Rails 3.1?

* Engine is now rack application * Added middleware stack to Engine* Engine can now load plugins* Engine can load its own environment file* Added helpers to call engines' route helpers from application and vice versa

Page 18: Railties

What to expect from Rails 3.1?

* Task for copying plugins' and engines' migrations to application's db/migrate directory* Changed ActionDispatch::Static to allow handling multiple directories* Added namespace() method to Engine, which sets Engine as isolated* Include all helpers from plugins and shared engines in application

Page 19: Railties

Good news

It looks Rails 3.1 will probably be very friendly for multible/mountable apps.

Page 20: Railties

Bad news

Please, don't go crazy with mountable apps,even with Rails 3.1

In my reality it's a pipe dream to create and use very high level dependencies.

Page 21: Railties

However there is nish

Take a look how Devise works and what kind workflow/attitude José Valim has.

He has given a nice introduction about this topic in Barcelona, probably there will be something on online as well.

Page 22: Railties

Thank you for you time!

Any questions or comments?

Just in case, here is my profiles:Github.com/priitTwitter.com/priithttp://priit.mx.ee

[email protected]