Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

find railties by name

#4264

Very simple 1-liner method to find railties and engines by name.

module Rotary
  class Wankle < Rails::Engine
    engine_name :wankle
  end
end
Rails::Engine.named(:wankle) # => Rotary::Wankle

Reported by Josh Susser · March 25th, 2010 @ 06:18 AM

State: committed
Milestone: 3.0.2
Assigned to: José Valim José Valim
Importance: Low

Activity

  1. Josh Susser
    Josh Susser
    • Tag changed from railties to patch, railties

    March 25th, 2010 @ 06:23 AM

  2. Josh Susser
  3. José Valim
    José Valim
    • Milestone cleared.
    • State changed from new to open
    • Assigned user changed from Yehuda Katz (wycats) to José Valim

    Could you provide an use case please?

    March 26th, 2010 @ 12:08 AM

  4. Josh Susser
    Josh Susser

    I need this for my patch to run migrations within engines, to allow identifying an engine by name. Seemed to make sense to make it a separate patch.

    March 26th, 2010 @ 04:31 AM

  5. José Valim
    José Valim

    Good reason and excellent idea to make a separate patch. I really just wanted to understand the use case (and yours is good). I will apply it soon. :)

    March 26th, 2010 @ 08:21 AM

  6. Jeremy Kemper
    Jeremy Kemper
    • State changed from open to committed

    http://github.com/rails/rails/commit/7b8399b80cfff58cfe2313187ca3c8...

    I'm not a fan of this. Names were optional before, only used for config.pluginname.* and I'd rather keep it that way. Use the class name for lookup.

    March 26th, 2010 @ 02:58 PM

  7. Josh Susser
    Josh Susser

    Jeremy, what's the downside? Names are still optional when creating railties/engines - if you don't specify one the railtie gets assigned the default name based on its class name. But allowing use of a developer-assigned name means you can drop in a replacement class that follows the same API. Example: engine Basic::UserAuthSystem is named :user_auth. I like SuperFantastic::UserAuthentication. If other engines only refer to it using the symbolic name, you don't have to do FactoryFactory tricks in your code to use an alternate implementation.

    March 26th, 2010 @ 03:41 PM

  8. Jeremy Kemper
    Jeremy Kemper

    The default naming will be removed soon, too :)

    It's only there to provide a config.defaultname which most plugins don't use.

    I like the drop-in replacement idea, but I think that's more likely to cause collisions than intentional drop-in. There's probably a better API for this.

    March 26th, 2010 @ 04:35 PM

  9. Yehuda Katz (wycats)
    Yehuda Katz (wycats)

    @jeremy what's the problem with this for cases only where a name is provided?

    March 26th, 2010 @ 06:28 PM

  10. José Valim
    José Valim

    The main problem by adding a method that searches by name, is that people will think they are required to give a name.

    If the case is about migrations, I guess we could have a configuration where a railtie could explicitly say the name to be used in migrations or do something like Jeremy suggested.

    March 26th, 2010 @ 06:32 PM

  11. José Valim
    José Valim

    I just reverted the commit and removed the naming in favor of "config.railtie_name = {}".

    March 26th, 2010 @ 06:34 PM

  12. Jeremy Kemper
    Jeremy Kemper
    • Milestone set to 3.0.2
    • Importance changed from to Low

    October 15th, 2010 @ 11:01 PM