Created
August 17, 2012 17:16
-
-
Save acook/3380730 to your computer and use it in GitHub Desktop.
Recursive mass require files with only a relative path.
Just require the `require_path_method.rb` file or copy/paste the contents into your project to use it.
The `oneliner.rb` script performs identically to the full `requirepath.rb` script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ pwd | |
/Users/acook/Projects/personal/3380730 | |
$ bash makepaths.sh | |
-- current_file: requirepath.rb | |
-- relative_path_of_current_file: . | |
-- path: /Users/acook/Projects/personal/3380730 | |
-- filematch: /Users/acook/Projects/personal/3380730/features/support/**/*.rb | |
-- file: /Users/acook/Projects/personal/3380730/features/support/whatever/something.rb | |
-- required: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Dir[File.expand_path('..', File.dirname(__FILE__)) + '/features/support/**/*.rb'].map{|file| require file} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def require_path relative_path | |
Dir[File.expand_path('..', File.dirname(__FILE__)) + File.join(relative_path, '**', '*.rb')].map{|file| require file} | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def out *args | |
puts "-- #{args.shift}: #{args.join(' ')}" | |
end | |
def stuff | |
current_file = __FILE__ | |
out :current_file, current_file | |
relative_path_of_current_file = File.dirname current_file | |
out :relative_path_of_current_file, relative_path_of_current_file | |
path = File.expand_path '..', relative_path_of_current_file | |
out :path, path | |
filematch = File.join path, "features/support/**/*.rb" | |
out :filematch, filematch | |
Dir[filematch].each do |file| | |
out :file, file | |
out :required, require(file) | |
end | |
end | |
stuff |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!bash | |
mkdir -p features/support/whatever | |
touch features/support/whatever/something.rb | |
mkdir scripts | |
cp requirepath.rb scripts/ | |
cd scripts | |
ruby requirepath.rb | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment