Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Conversation

knf
Copy link

@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
Copy link
Contributor

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
Copy link
Author

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
Copy link
Contributor

-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
Copy link
Author

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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants