Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module ConstMissingHelper
- extend ActiveSupport::Concern
- included do
- cattr_accessor :constant_paths
- self.const_paths = []
- extend ConstMissingHelper::ClassMethods
- end
- module ClassMethods
- def constant_defined_by_file?(const_name)
- const_paths.detect do |path|
- full_path = Rails.root+"#{path}/#{name.underscore}/#{const_name.to_s.underscore}.rb"
- paths = Pathname.glob full_path.to_s
- Rails.logger.debug "Missing Admin Controller constant is defined by #{full_path}? #{paths.dectect(&:file?).inspect}"
- paths.detect &:file?
- end
- end
- def const_path(path)
- const_paths << path
- end
- def define_missing_constant(const_name, superclass=Object)
- Rails.logger.debug "Define Missing Constant #{name}::#{const_name} < #{superclass} @ #{caller.first}"
- const_set(name, Class.new(superclass))
- end
- end
- end
Add Comment
Please, Sign In to add comment