Created
November 20, 2016 02:09
-
-
Save awoodworth/bc7d9295848a150f715f291677ad82b8 to your computer and use it in GitHub Desktop.
Rails - Reload Classes
This file contains 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
class Setting < ActiveRecord::Base | |
validates :name, :value, presence: true | |
validates :name, uniqueness: true | |
after_update :reload_classes | |
#.. | |
private | |
# reload_classes is a hack way around loading settings into FINALS | |
def reload_classes | |
klasses = [:User, :Group] | |
# unload classes | |
Object.class_eval do | |
klasses.each do |klass| | |
remove_const klass.to_s if const_defined? klass.to_s | |
end | |
end | |
# reload classes | |
klasses.each do |klass| | |
load "#{klass.to_s.underscore}.rb" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment