Skip to content

Instantly share code, notes, and snippets.

@bsa7
Created August 15, 2022 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bsa7/65ad1d80298eba57bd4ef7f72d3d2c2c to your computer and use it in GitHub Desktop.
Save bsa7/65ad1d80298eba57bd4ef7f72d3d2c2c to your computer and use it in GitHub Desktop.
Check intersections in method names of Rails helpers
# frozen_string_literal: true
# You would to run `HelpersMethods.new.call` as Rails class from rails console
class HelpersMethods
def call
helper_files = Dir.glob(Rails.root.join('app/helpers/**/*.rb'))
helpers_methods = {}
intersections = {}
helper_files.each do |file_name|
helper_name = file_name.sub(/^.+app\/helpers\//, '').sub(/\.rb$/, '').camelize
helper_module = helper_name.constantize
helper_methods = helper_module.instance_methods(false) | helper_module.private_instance_methods(false)
helpers_methods[helper_name] = helper_methods
end
helpers_methods.each_key do |helper_name|
(helpers_methods.keys - [helper_name]).each do |compared_helper_name|
next if intersections.key?(compared_helper_name)
intersected_methods = helpers_methods[helper_name] & helpers_methods[compared_helper_name]
next if intersected_methods.blank?
intersections[helper_name] ||= {}
intersections[helper_name][compared_helper_name] = intersected_methods
end
end
ap intersections
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment