Module: ActiveSupport::Dependencies::ModuleConstMissing

Defined in:
activesupport/lib/active_support/dependencies.rb

Overview

Module includes this module.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.append_features(base) ⇒ Object



190
191
192
193
194
195
196
197
198
# File 'activesupport/lib/active_support/dependencies.rb', line 190

def self.append_features(base)
  base.class_eval do
    # Emulate #exclude via an ivar
    return if defined?(@_const_missing) && @_const_missing
    @_const_missing = instance_method(:const_missing)
    remove_method(:const_missing)
  end
  super
end

.exclude_from(base) ⇒ Object



200
201
202
203
204
205
# File 'activesupport/lib/active_support/dependencies.rb', line 200

def self.exclude_from(base)
  base.class_eval do
    define_method :const_missing, @_const_missing
    @_const_missing = nil
  end
end

.include_into(base) ⇒ Object



207
208
209
210
# File 'activesupport/lib/active_support/dependencies.rb', line 207

def self.include_into(base)
  base.include(self)
  append_features(base)
end

Instance Method Details

#const_missing(const_name) ⇒ Object



212
213
214
215
# File 'activesupport/lib/active_support/dependencies.rb', line 212

def const_missing(const_name)
  from_mod = anonymous? ? guess_for_anonymous(const_name) : self
  Dependencies.load_missing_constant(from_mod, const_name)
end

#guess_for_anonymous(const_name) ⇒ Object

We assume that the name of the module reflects the nesting (unless it can be proven that is not the case) and the path to the file that defines the constant. Anonymous modules cannot follow these conventions and therefore we assume that the user wants to refer to a top-level constant.



222
223
224
225
226
227
228
# File 'activesupport/lib/active_support/dependencies.rb', line 222

def guess_for_anonymous(const_name)
  if Object.const_defined?(const_name)
    raise NameError.new "#{const_name} cannot be autoloaded from an anonymous class or module", const_name
  else
    Object
  end
end

#unloadable(const_desc = self) ⇒ Object



230
231
232
# File 'activesupport/lib/active_support/dependencies.rb', line 230

def unloadable(const_desc = self)
  super(const_desc)
end