Created a custom module generator. Generates a stub for a module in lib and an associated test #4032

Closed
wants to merge 2 commits into
from

Projects

None yet

2 participants

@knf
knf commented Dec 19, 2011

Description:
Stubs out a new module in the lib directory. Pass in the module name and a list of optional method names.
This is useful when writing custom modules for use in multiple models etc.
This generates a custom module file in lib as well as a test in test/unit.

Example:
rails generate module custom method1 method2 method3

    Task:      lib/custom.rb
    Test:      test/unit/custom_test.rb
@josevalim
Member

Thanks but I am not very keen on this PR. What if you want to create a class? Where is the lib file being required? Honestly, this is easier to be handled manually.

@knf
knf commented Dec 19, 2011

Well my next thought was to create a class generator using the same pattern. I could add a file require statement in application.rb, something like: config.autoload_paths += Dir["#{config.root}/lib/**/"]

I could also combine module and class generators into one generator. eg. rails generate file:class_name or rails generate file:module_name

@josevalim
Member

-1 for autoload, we have removed it explicitly because lib code should not be autoloaded. And -1 for another generator for a class. Thanks for your contributions but I don't think we need any automation on this part.

@josevalim josevalim closed this Dec 19, 2011
@knf
knf commented Dec 19, 2011

Gotcha. Thanks for the feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment