Module: ActiveSupport::Dependencies::ModuleConstMissing
- Defined in:
- lib/active_support/dependencies.rb
Overview
Module includes this module
Class Method Summary collapse
Instance Method Summary collapse
-
#const_missing(const_name, nesting = nil) ⇒ Object
Use const_missing to autoload associations so we don’t have to require_association when using single-table inheritance.
- #unloadable(const_desc = self) ⇒ Object
Class Method Details
.append_features(base) ⇒ Object
:nodoc:
120 121 122 123 124 125 126 127 128 |
# File 'lib/active_support/dependencies.rb', line 120 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
130 131 132 133 134 135 |
# File 'lib/active_support/dependencies.rb', line 130 def self.exclude_from(base) base.class_eval do define_method :const_missing, @_const_missing @_const_missing = nil end end |
Instance Method Details
#const_missing(const_name, nesting = nil) ⇒ Object
Use const_missing to autoload associations so we don’t have to require_association when using single-table inheritance.
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/active_support/dependencies.rb', line 139 def const_missing(const_name, nesting = nil) klass_name = name.presence || "Object" if !nesting # We'll assume that the nesting of Foo::Bar is ["Foo::Bar", "Foo"] # even though it might not be, such as in the case of # class Foo::Bar; Baz; end nesting = [] klass_name.to_s.scan(/::|$/) { nesting.unshift $` } end # If there are multiple levels of nesting to search under, the top # level is the one we want to report as the lookup fail. error = nil nesting.each do |namespace| begin return Dependencies.load_missing_constant namespace.constantize, const_name rescue NoMethodError then raise rescue NameError => e error ||= e end end # Raise the first error for this set. If this const_missing came from an # earlier const_missing, this will result in the real error bubbling # all the way up raise error end |
#unloadable(const_desc = self) ⇒ Object
169 170 171 |
# File 'lib/active_support/dependencies.rb', line 169 def unloadable(const_desc = self) super(const_desc) end |