Skip to content

Instantly share code, notes, and snippets.

@u007
Last active July 24, 2016 13:14
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 u007/47b2f021670d54f862624ae70494a085 to your computer and use it in GitHub Desktop.
Save u007/47b2f021670d54f862624ae70494a085 to your computer and use it in GitHub Desktop.
fix for padrino with activerecord concern reload issue
Padrino::Reloader.module_eval do
def reload!
list = []
extras = []
rotation do |file|
next unless file_changed?(file)
list << file
end
if Module.const_get("ActiveRecord").is_a?(Module)
list.each do |file|
unless file.index('concerns/').nil?
name = Pathname.new(file).basename.to_s.gsub('.rb', '').gsub('.rake', '')
# puts "basename: #{name.inspect}"
concern_klass = ActiveSupport::Inflector.constantize(
ActiveSupport::Inflector.classify(name)
)
# logger.info "is concern: #{file}, klass: #{concern_klass}"
# is a concern, reload all
ActiveRecord::Base.descendants.each do |klass|
# logger.info "class: #{klass.inspect}"
if klass.included_modules.include?(concern_klass)
find_file = Padrino.root('models/'+klass.name.underscore+".rb")
logger.devel "model included: #{find_file}"
if File.exists?(find_file)
unless list.include?(find_file) || extras.include?(find_file)
extras << find_file
end
# remove model class due to concern
remove_constant(klass)
else
logger.error "model file missing: #{find_file}"
end
end
end
# time to remove concern
remove_constant(concern_klass)
end
end
end
# logger.info "list: #{list.inspect}, extras: #{extras}"
list.each do |file|
reload_special(file) || reload_regular(file)
end
extras.each do |file|
logger.devel "RELOAD MODEL #{file}"
reload_special(file) || reload_regular(file)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment