Class: ActiveSupport::Dependencies::WatchStack

### Home Classes Methods

### In Files

- lib/active_support/dependencies.rb

### Parent

Object

### Methods

- ::new
- #each
- #new_constants
- #watch_namespaces
- #watching?

### Included Modules

- Enumerable

### Class/Module Index

Quicksearch

- ActiveSupport
- ActiveSupport::Autoload
- ActiveSupport::BacktraceCleaner
- ActiveSupport::Base64
- ActiveSupport::BasicObject
- ActiveSupport::Benchmarkable
- ActiveSupport::BufferedLogger
- ActiveSupport::BufferedLogger::Severity
- ActiveSupport::Cache
- ActiveSupport::Cache::Entry
- ActiveSupport::Cache::FileStore
- ActiveSupport::Cache::MemCacheStore
- ActiveSupport::Cache::MemoryStore
- ActiveSupport::Cache::NullStore
- ActiveSupport::Cache::Store
- ActiveSupport::Cache::Strategy
- ActiveSupport::Cache::Strategy::LocalCache
- ActiveSupport::Cache::Strategy::LocalCache::LocalStore
- ActiveSupport::Callbacks
- ActiveSupport::Callbacks::ClassMethods
- ActiveSupport::Concern
- ActiveSupport::Configurable
- ActiveSupport::Configurable::ClassMethods
- ActiveSupport::Configurable::Configuration
- ActiveSupport::Dependencies
- ActiveSupport::Dependencies::ClassCache
- ActiveSupport::Dependencies::WatchStack
- ActiveSupport::Deprecation
- ActiveSupport::DescendantsTracker
- ActiveSupport::Duration
- ActiveSupport::FileUpdateChecker
- ActiveSupport::FileWatcher
- ActiveSupport::FileWatcher::Backend
- ActiveSupport::Gzip
- ActiveSupport::Gzip::Stream
- ActiveSupport::HashWithIndifferentAccess
- ActiveSupport::HashWithIndifferentAccess
- ActiveSupport::Inflector
- ActiveSupport::Inflector::Inflections
- ActiveSupport::InheritableOptions
- ActiveSupport::JSON
- ActiveSupport::JSON::Encoding
- ActiveSupport::JSON::Encoding::CircularReferenceError
- ActiveSupport::JSON::Encoding::Encoder
- ActiveSupport::JSON::Variable
- ActiveSupport::LogSubscriber
- ActiveSupport::LogSubscriber::TestHelper
- ActiveSupport::LogSubscriber::TestHelper::MockLogger
- ActiveSupport::Memoizable
- ActiveSupport::Memoizable::InstanceMethods
- ActiveSupport::MessageEncryptor
- ActiveSupport::MessageEncryptor::InvalidMessage
- ActiveSupport::MessageVerifier
- ActiveSupport::MessageVerifier::InvalidSignature
- ActiveSupport::Multibyte
- ActiveSupport::Multibyte::Chars
- ActiveSupport::Multibyte::EncodingError
- ActiveSupport::Multibyte::Unicode
- ActiveSupport::Multibyte::Unicode::Codepoint
- ActiveSupport::Multibyte::Unicode::UnicodeDatabase
- ActiveSupport::Notifications
- ActiveSupport::Notifications::Event
- ActiveSupport::Notifications::Fanout
- ActiveSupport::Notifications::Instrumenter
- ActiveSupport::OrderedHash
- ActiveSupport::OrderedOptions
- ActiveSupport::Railtie
- ActiveSupport::Rescuable
- ActiveSupport::Rescuable::ClassMethods
- ActiveSupport::SafeBuffer
- ActiveSupport::SafeBuffer::SafeConcatError
- ActiveSupport::StringInquirer
- ActiveSupport::TaggedLogging
- ActiveSupport::TestCase
- ActiveSupport::Testing
- ActiveSupport::Testing::Assertions
- ActiveSupport::Testing::Declarative
- ActiveSupport::Testing::Isolation
- ActiveSupport::Testing::Isolation::Forking
- ActiveSupport::Testing::Isolation::MiniTest
- ActiveSupport::Testing::Isolation::Subprocess
- ActiveSupport::Testing::Isolation::TestUnit
- ActiveSupport::Testing::Pending
- ActiveSupport::Testing::Performance
- ActiveSupport::Testing::Performance::Benchmarker
- ActiveSupport::Testing::Performance::ForClassicTestUnit
- ActiveSupport::Testing::Performance::ForMiniTest
- ActiveSupport::Testing::Performance::Metrics
- ActiveSupport::Testing::Performance::Metrics::Amount
- ActiveSupport::Testing::Performance::Metrics::Base
- ActiveSupport::Testing::Performance::Metrics::CpuTime
- ActiveSupport::Testing::Performance::Metrics::DigitalInformationUnit
- ActiveSupport::Testing::Performance::Metrics::GcRuns
- ActiveSupport::Testing::Performance::Metrics::GcTime
- ActiveSupport::Testing::Performance::Metrics::Memory
- ActiveSupport::Testing::Performance::Metrics::Objects
- ActiveSupport::Testing::Performance::Metrics::ProcessTime
- ActiveSupport::Testing::Performance::Metrics::Time
- ActiveSupport::Testing::Performance::Metrics::UserTime
- ActiveSupport::Testing::Performance::Metrics::WallTime
- ActiveSupport::Testing::Performance::Performer
- ActiveSupport::Testing::Performance::Profiler
- ActiveSupport::Testing::ProxyTestResult
- ActiveSupport::Testing::RemoteError
- ActiveSupport::Testing::SetupAndTeardown
- ActiveSupport::Testing::SetupAndTeardown::ClassMethods
- ActiveSupport::Testing::SetupAndTeardown::ForClassicTestUnit
- ActiveSupport::Testing::SetupAndTeardown::ForMiniTest
- ActiveSupport::TimeWithZone
- ActiveSupport::TimeZone
- ActiveSupport::XmlMini
- ActiveSupport::XmlMini_LibXMLSAX
- ActiveSupport::XmlMini_LibXMLSAX::HashBuilder
- ActiveSupport::XmlMini_NokogiriSAX
- ActiveSupport::XmlMini_NokogiriSAX::HashBuilder
- Test
- Test::Unit
- Test::Unit::Collector
- Test::Unit::Collector::ObjectSpace
- Object
- Object::HashWithIndifferentAccess
- Object::MissingSourceFile
- ERB
- ERB::Util
- I18n
- I18n::Railtie
- LoadError
- LoadError
- Logger
- Logger::SimpleFormatter
- Array
- Base64
- Benchmark
- BigDecimal
- Class
- Date
- DateTime
- Enumerable
- FalseClass
- File
- Float
- Hash
- Integer
- Kernel
- Module
- NameError
- NilClass
- Numeric
- Process
- QualifiedConstUtils
- Range
- Regexp
- String
- Symbol
- Time
- TrueClass
- URI

No matching classes.

# ActiveSupport::Dependencies::WatchStack

The WatchStack keeps a stack of the modules being watched as files are loaded. If a file in the process of being loaded (parent.rb) triggers the load of another file (child.rb) the stack will ensure that child.rb handles the new constants.

If child.rb is being autoloaded, its constants will be added to autoloaded_constants. If it was being `require`d, they will be discarded.

This is handled by walking back up the watch stack and adding the constants found by child.rb to the list of original constants in parent.rb

### Public Class Methods

new() click to toggle source

@watching is a stack of lists of constants being watched. For instance, if parent.rb is autoloaded, the stack will look like [[Object]]. If parent.rb then requires namespace/child.rb, the stack will look like [[Object], [Namespace]].

    # File lib/active_support/dependencies.rb, line 81
    def initialize
      @watching = []
      @stack = Hash.new { |h,k| h[k] = [] }
    end

### Public Instance Methods

each(&block) click to toggle source

    # File lib/active_support/dependencies.rb, line 86
    def each(&block)
      @stack.each(&block)
    end

new_constants() click to toggle source

return a list of new constants found since the last call to watch_namespaces

    # File lib/active_support/dependencies.rb, line 95
    def new_constants
      constants = []

      # Grab the list of namespaces that we're looking for new constants under
      @watching.last.each do |namespace|
        # Retrieve the constants that were present under the namespace when watch_namespaces
        # was originally called
        original_constants = @stack[namespace].last

        mod = Inflector.constantize(namespace) if Dependencies.qualified_const_defined?(namespace)
        next unless mod.is_a?(Module)

        # Get a list of the constants that were added
        new_constants = mod.local_constant_names - original_constants

        # self[namespace] returns an Array of the constants that are being evaluated
        # for that namespace. For instance, if parent.rb requires child.rb, the first
        # element of self[Object] will be an Array of the constants that were present
        # before parent.rb was required. The second element will be an Array of the
        # constants that were present before child.rb was required.
        @stack[namespace].each do |namespace_constants|
          namespace_constants.concat(new_constants)
        end

        # Normalize the list of new constants, and add them to the list we will return
        new_constants.each do |suffix|
          constants << ([namespace, suffix] - ["Object"]).join("::")
        end
      end
      constants
    ensure
      # A call to new_constants is always called after a call to watch_namespaces
      pop_modules(@watching.pop)
    end

watch_namespaces(namespaces) click to toggle source

Add a set of modules to the watch stack, remembering the initial constants

    # File lib/active_support/dependencies.rb, line 131
    def watch_namespaces(namespaces)
      watching = []
      namespaces.map do |namespace|
        module_name = Dependencies.to_constant_name(namespace)
        original_constants = Dependencies.qualified_const_defined?(module_name) ?
          Inflector.constantize(module_name).local_constant_names : []

        watching << module_name
        @stack[module_name] << original_constants
      end
      @watching << watching
    end

watching?() click to toggle source

    # File lib/active_support/dependencies.rb, line 90
    def watching?
      !@watching.empty?
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.