Created
December 7, 2016 17:17
-
-
Save TheRusskiy/26a2552148d3cd2a798555081cab5a62 to your computer and use it in GitHub Desktop.
List all Rails helper methods
This file contains hidden or 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 get_helper_modules(subtree = []) | |
helper_directory = Rails.root.join('app').join('helpers') | |
subtree.each do |folder| | |
helper_directory = helper_directory.join(folder) | |
end | |
entries = Dir.entries(helper_directory) - %w(. ..) | |
files = entries.select { |e| e.include?('.rb') } | |
modules = files.map do |file| | |
module_name = subtree.map(&:camelcase).join('::') | |
if module_name.present? | |
module_name += '::' | |
end | |
class_name = file.gsub('.rb', '').camelcase | |
(module_name + class_name).constantize | |
end | |
directores = entries.reject { |e| e.include?('.rb') } | |
directores.each do |dir| | |
modules.concat get_helper_modules(subtree + [dir]) | |
end | |
modules | |
end | |
methods = get_helper_modules.map(&:public_instance_methods).flatten | |
puts methods |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment