Created
January 1, 2025 07:02
-
-
Save nwxxb/6c14ba367846cf552c1a0f671c61fa7b to your computer and use it in GitHub Desktop.
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
| # WIP | |
| # it currently can't detect suffix, prefix, and scope attribute provided to your enum invocation | |
| # and if you use values that are reserved in ruby (like reject, create, etc...) you will get a problem using this script | |
| # TL;DR you will end up need to filter it yourself/manually delete it | |
| # I assume that you fill this array with the model's file name with extension omitted | |
| ["user", "product"].each.with_index(1) do |model_file_name, index| | |
| model_constant = Object.const_get(model_file_name.camelize) | |
| puts "#{index}. #{model_constant}" | |
| class_methods = model_constant.methods.select do |method_sym| | |
| method_str = method_sym.to_s | |
| method_str.match(/(s|es)$/) && model_constant.column_names.include?(method_str.singularize) | |
| end - [:ids] | |
| class_methods.each do |method_sym| | |
| enum_hash = model_constant.send(method_sym) | |
| puts " - `.#{method_sym}` => #{enum_hash}" | |
| enum_hash.keys.each do |key| | |
| puts model_constant.instance_methods.select do |instance_method_sym| | |
| instance_method_sym.to_s.include?(key) | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment