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
-
#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
156 157 158 159 160 161 162 163 164 |
# File 'activesupport/lib/active_support/dependencies.rb', line 156 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
166 167 168 169 170 171 |
# File 'activesupport/lib/active_support/dependencies.rb', line 166 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.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'activesupport/lib/active_support/dependencies.rb', line 175 def const_missing(const_name, nesting = nil) klass_name = name.presence || "Object" unless 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 Inflector.constantize(namespace), 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
205 206 207 |
# File 'activesupport/lib/active_support/dependencies.rb', line 205 def unloadable(const_desc = self) super(const_desc) end |