Guest User

Untitled

a guest
May 25th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. module ConstMissingHelper
  2. extend ActiveSupport::Concern
  3. included do
  4. cattr_accessor :constant_paths
  5. self.const_paths = []
  6. extend ConstMissingHelper::ClassMethods
  7. end
  8.  
  9. module ClassMethods
  10. def constant_defined_by_file?(const_name)
  11. const_paths.detect do |path|
  12. full_path = Rails.root+"#{path}/#{name.underscore}/#{const_name.to_s.underscore}.rb"
  13. paths = Pathname.glob full_path.to_s
  14. Rails.logger.debug "Missing Admin Controller constant is defined by #{full_path}? #{paths.dectect(&:file?).inspect}"
  15. paths.detect &:file?
  16. end
  17. end
  18.  
  19. def const_path(path)
  20. const_paths << path
  21. end
  22.  
  23. def define_missing_constant(const_name, superclass=Object)
  24. Rails.logger.debug "Define Missing Constant #{name}::#{const_name} < #{superclass} @ #{caller.first}"
  25. const_set(name, Class.new(superclass))
  26. end
  27. end
  28. end
Add Comment
Please, Sign In to add comment