Skip to content

Instantly share code, notes, and snippets.

@u007 u007/config - boot.rb
Last active Jul 24, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.