Skip to content

Instantly share code, notes, and snippets.

@iftheshoefritz
Created June 16, 2020 14:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iftheshoefritz/4bf1980a686123f47e99fa5a21b190ab to your computer and use it in GitHub Desktop.
Save iftheshoefritz/4bf1980a686123f47e99fa5a21b190ab to your computer and use it in GitHub Desktop.
namespace :solargraph do
task update_model_definitions: :environment do
if Rails.env.development?
Rails.application.eager_load!
def_file = Rails.root.join('config', 'model_definitions.rb')
File.open(def_file, 'w') do |file|
ApplicationRecord.descendants.each do |model|
file << "class #{model.name}\n"
klass = model.name.constantize
klass.attribute_names.each do |name|
file << "# @!attribute [rw] #{name}\n"
file << "# @return [#{ruby_type[klass.type_for_attribute(name).type]}]\n"
end
file << "end\n"
end
end
end
end
end
def ruby_type
{
array: 'Array',
boolean: 'Boolean',
date: 'Date',
datetime: 'DateTime',
decimal: 'Decimal',
float: 'Float',
integer: 'Integer',
string: 'String',
text: 'String',
time: 'Time',
}
end
@julianrubisch
Copy link

I had to do
Zeitwerk::Loader.eager_load_all if Zeitwerk instead of Rails.application.eager_load! to get it working on Rails 6 app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment