Module: Padrino::Reloader

### Home Classes Methods

### In Files

- lib/padrino-core/cli/rake_tasks.rb
- lib/padrino-core/reloader.rb
- lib/padrino-core/reloader/rack.rb
- lib/padrino-core/reloader/storage.rb

### Namespace

- MODULE Padrino::Reloader::Storage
- CLASS Padrino::Reloader::Rack

### Methods

- ::safe_load
- #changed?
- #clear!
- #exclude
- #exclude_constants
- #include_constants
- #lock!
- #reload!
- #remove_constant
- #remove_feature
- #safe_load
- #special_files
- #special_files=
- #unknown

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- Padrino
- Padrino::Application
- Padrino::ApplicationLoadError
- Padrino::ApplicationSetup
- Padrino::ApplicationSetup::ClassMethods
- Padrino::AuthenticityToken
- Padrino::Cli
- Padrino::Cli::Adapter
- Padrino::Cli::Base
- Padrino::Cli::Launcher
- Padrino::Filter
- Padrino::Flash
- Padrino::Flash::Helpers
- Padrino::Flash::Storage
- Padrino::Loader
- Padrino::Logger
- Padrino::Logger::Colorize
- Padrino::Logger::Extensions
- Padrino::Logger::Rack
- Padrino::Module
- Padrino::Mounter
- Padrino::Mounter::ApplicationWrapper
- Padrino::Mounter::MounterException
- Padrino::ParamsProtection
- Padrino::ParamsProtection::ClassMethods
- Padrino::ParamsProtection::InstanceMethods
- Padrino::Reloader
- Padrino::Reloader::Rack
- Padrino::Reloader::Storage
- Padrino::Router
- Padrino::Routing
- Padrino::Routing::ClassMethods
- Padrino::Routing::InstanceMethods
- Padrino::Routing::Parent
- Padrino::Routing::UnrecognizedException
- Padrino::Server
- Padrino::ShowExceptions
- Padrino::Tasks
- HttpRouter
- HttpRouter::Node
- HttpRouter::Node::FreeRegex
- HttpRouter::Node::Glob
- HttpRouter::Node::Path
- HttpRouter::Node::SpanningRegex
- HttpRouter::Request
- HttpRouter::Route
- Sinatra
- Sinatra::Base
- Sinatra::Request
- Kernel
- Object
- PadrinoTasks

No matching classes.

# Padrino::Reloader

High performance source code reloader middleware

### Constants

MTIMES

  The modification times for every file in a project.

### Public Class Methods

safe_load(file, options) click to toggle source

    # File lib/padrino-core/cli/rake_tasks.rb, line 22
    def self.safe_load(file, options)
      super unless file.include?('/models/')
    end

### Public Instance Methods

changed?() click to toggle source

Returns true if any file changes are detected.

    # File lib/padrino-core/reloader.rb, line 66
    def changed?
      rotation do |file|
        break true if file_changed?(file)
      end
    end

clear!() click to toggle source

Remove files and classes loaded with stat

    # File lib/padrino-core/reloader.rb, line 58
    def clear!
      MTIMES.clear
      Storage.clear!
    end

exclude() click to toggle source

Specified folders can be excluded from the code reload detection process. Default excluded directories at Padrino.root are: test, spec, features, tmp, config, db and public

    # File lib/padrino-core/reloader.rb, line 26
    def exclude
      @_exclude ||= Set.new %(test spec tmp features config public db).map{ |path| Padrino.root(path) }
    end

exclude_constants() click to toggle source

Specified constants can be excluded from the code unloading process.

    # File lib/padrino-core/reloader.rb, line 33
    def exclude_constants
      @_exclude_constants ||= Set.new
    end

include_constants() click to toggle source

Specified constants can be configured to be reloaded on every request. Default included constants are: [none]

    # File lib/padrino-core/reloader.rb, line 41
    def include_constants
      @_include_constants ||= Set.new
    end

lock!() click to toggle source

We lock dependencies sets to prevent reloading of protected constants

    # File lib/padrino-core/reloader.rb, line 75
    def lock!
      klasses = ObjectSpace.classes do |klass|
        klass._orig_klass_name.split('::').first
      end
      klasses |= Padrino.mounted_apps.map(&:app_class)
      exclude_constants.merge(klasses)
    end

reload!() click to toggle source

Reload apps and files with changes detected.

    # File lib/padrino-core/reloader.rb, line 48
    def reload!
      rotation do |file|
        next unless file_changed?(file)
        reload_special(file) || reload_regular(file)
      end
    end

remove_constant(const) click to toggle source

Removes the specified class and constant.

    # File lib/padrino-core/reloader.rb, line 111
    def remove_constant(const)
      return if constant_excluded?(const)
      base, _, object = const.to_s.rpartition('::')
      base = base.empty? ? Object : base.constantize
      base.send :remove_const, object
      logger.devel "Removed constant #{const} from #{base}"
    rescue NameError
    end

remove_feature(file) click to toggle source

Remove a feature from $LOADED_FEATURES so it can be required again.

    # File lib/padrino-core/reloader.rb, line 123
    def remove_feature(file)
      $LOADED_FEATURES.delete(file) unless feature_excluded?(file)
    end

safe_load(file, options={}) click to toggle source

A safe Kernel::require which issues the necessary hooks depending on results

    # File lib/padrino-core/reloader.rb, line 86
    def safe_load(file, options={})
      began_at = Time.now
      file     = figure_path(file)
      return unless options[:force] || file_changed?(file)
      return require(file) if feature_excluded?(file)

      Storage.prepare(file) # might call #safe_load recursively
      logger.devel(file_new?(file) ? :loading : :reload, began_at, file)
      begin
        with_silence{ require(file) }
        Storage.commit(file)
        update_modification_time(file)
      rescue Exception => exception
        unless options[:cyclic]
          logger.exception exception, :short
          logger.error "Failed to load #{file}; removing partially defined constants"
        end
        Storage.rollback(file)
        raise
      end
    end

special_files() click to toggle source

Returns the list of special tracked files for Reloader.

    # File lib/padrino-core/reloader.rb, line 130
    def special_files
      @special_files ||= Set.new
    end

special_files=(files) click to toggle source

Sets the list of special tracked files for Reloader.

    # File lib/padrino-core/reloader.rb, line 137
    def special_files=(files)
      @special_files = Set.new(files)
    end

unknown click to toggle source

This reloader is suited for use in a many environments because each file will only be checked once and only one system call to stat(2) is made.

Please note that this will not reload files in the background, and does so only when explicitly invoked.

    # File lib/padrino-core/reloader.rb, line 17
    extend self

[Validate]

Generated with the Darkfish Rdoc Generator 2.