Class: Ramaze::Reloader

### Home Classes Methods

### In Files

- lib/ramaze/reloader.rb
- lib/ramaze/reloader/watch_inotify.rb
- lib/ramaze/reloader/watch_stat.rb

### Parent

Object

### Namespace

- MODULE Ramaze::Reloader::Hooks
- CLASS Ramaze::Reloader::WatchInotify
- CLASS Ramaze::Reloader::WatchStat

### Methods

- ::new
- #call
- #cycle
- #figure_path
- #options_reload
- #rotation
- #safe_load

### Included Modules

- Ramaze::Reloader::Hooks

### Files

- Gemfile
- Rakefile

### Class/Module Index

Quicksearch

- Ramaze
- Ramaze::App
- Ramaze::Bin
- Ramaze::Bin::Create
- Ramaze::Bin::Runner
- Ramaze::Cache
- Ramaze::Cache::LRU
- Ramaze::Cache::LocalMemCache
- Ramaze::Cache::MemCache
- Ramaze::Cache::Redis
- Ramaze::Cache::Sequel
- Ramaze::Controller
- Ramaze::CoreExtensions
- Ramaze::CoreExtensions::Object
- Ramaze::CoreExtensions::String
- Ramaze::Current
- Ramaze::DefaultController
- Ramaze::Files
- Ramaze::Gestalt
- Ramaze::Helper
- Ramaze::Helper::Auth
- Ramaze::Helper::Bench
- Ramaze::Helper::BlueForm
- Ramaze::Helper::BlueForm::Form
- Ramaze::Helper::CSRF
- Ramaze::Helper::Cache
- Ramaze::Helper::Cache::SingletonMethods
- Ramaze::Helper::Email
- Ramaze::Helper::Erector
- Ramaze::Helper::Flash
- Ramaze::Helper::Formatting
- Ramaze::Helper::Gestalt
- Ramaze::Helper::Gravatar
- Ramaze::Helper::Identity
- Ramaze::Helper::Layout
- Ramaze::Helper::Layout::SingletonMethods
- Ramaze::Helper::Link
- Ramaze::Helper::Localize
- Ramaze::Helper::Localize::Dictionary
- Ramaze::Helper::Localize::Parser
- Ramaze::Helper::Markaby
- Ramaze::Helper::Maruku
- Ramaze::Helper::Paginate
- Ramaze::Helper::Paginate::Paginator
- Ramaze::Helper::Paginate::Paginator::ArrayPager
- Ramaze::Helper::Paginate::Paginator::DataMapperPager
- Ramaze::Helper::Remarkably
- Ramaze::Helper::RequestAccessor
- Ramaze::Helper::SendFile
- Ramaze::Helper::SimpleCaptcha
- Ramaze::Helper::Stack
- Ramaze::Helper::Thread
- Ramaze::Helper::Upload
- Ramaze::Helper::Upload::ClassMethods
- Ramaze::Helper::Upload::UploadedFile
- Ramaze::Helper::UserHelper
- Ramaze::Helper::UserHelper::Wrapper
- Ramaze::Helper::XHTML
- Ramaze::LRUHash
- Ramaze::Logger
- Ramaze::Logger::Informer
- Ramaze::Logger::LogHub
- Ramaze::Logger::Logger
- Ramaze::Logger::RotatingInformer
- Ramaze::Logger::Syslog
- Ramaze::Logging
- Ramaze::Reloader
- Ramaze::Reloader::Hooks
- Ramaze::Reloader::WatchInotify
- Ramaze::Reloader::WatchStat
- Ramaze::Request
- Ramaze::Response
- Ramaze::SpecLogger
- Ramaze::View
- Ramaze::View::Erector
- Ramaze::View::Erubis
- Ramaze::View::Ezamar
- Ramaze::View::Gestalt
- Ramaze::View::Haml
- Ramaze::View::Liquid
- Ramaze::View::Liquid::Tag
- Ramaze::View::Lokar
- Ramaze::View::Mustache
- Ramaze::View::Mustache::RamazeContext
- Ramaze::View::Nagoro
- Ramaze::View::Remarkably
- Ramaze::View::Sass
- Ramaze::View::Slippers
- Ramaze::View::Tagz
- Ramaze::View::Tagz::Methods
- Ramaze::View::Tenjin
- Innate
- Innate::View
- Innate::View::Slim
- Nagoro
- Nagoro::Pipe
- Nagoro::Pipe::RenderPartial
- Bacon
- Bacon::PrettyOutput
- Erector
- Erector::Widget
- Rack
- Rack::RouteExceptions
- Tenjin
- Tenjin::Template
- BlankSlate
- Controller
- MainController
- Object

No matching classes.

# Ramaze::Reloader

High performant source reloader

This class acts as Rack middleware.

It does not depend on Ramaze itself, but you might have to adjust the Reloader::Hooks module or include your own module to override the hooks. You also might have to set the Log constant.

Currently, it uses RInotify if available and falls back to using File.stat.

Please note that this will not reload files in the background, it does so only when actively called In case of Ramaze it is performing a check/reload cycle at the start of every request, but also respects a cool down time, during which nothing will be done.

After every reload the OPTIONS hash will be checked for changed options and assigned to the instance, so you may change options during the lifetime of your application.

A number of hooks will be executed during the reload cycle, see Ramaze::ReloaderHooks for more information.

### Constants

OPTIONS
Watcher

### Public Class Methods

new(app) click to toggle source

Creates a new instance of the class and saves the application it has to watch.

@author Michael Fellinger @since 09-08-2008 @param [Ramaze::App] app The application to monitor.

    # File lib/ramaze/reloader.rb, line 71
    def initialize(app)
      @app = app
      @files = {}
      @watcher = Watcher.new
      options_reload
    end

### Public Instance Methods

call(env) click to toggle source

Allows this class to be called as a Rack middleware.

@author Michael Fellinger @since 09-08-2008 @param [Hash] env A hash containing all environment details.

    # File lib/ramaze/reloader.rb, line 97
    def call(env)
      options_reload

      @watcher.call(@cooldown) do
        if @control
          instance_eval(&@control)
        elsif @thread
          Thread.exclusive{ cycle }
        else
          cycle
        end
      end

      @app.call(env)
    end

cycle() click to toggle source

Loops through all the files and reloads all changes files.

@author Michael Fellinger @since 09-08-2008

    # File lib/ramaze/reloader.rb, line 119
    def cycle
      before_cycle

      rotation{|file| @watcher.watch(file) }
      @watcher.changed_files{|f| safe_load(f) }

      after_cycle
    end

figure_path(file, paths) click to toggle source

Tries to find a given file in an array of file paths.

@author Michael Fellinger @since 09-08-2008 @param [String] file The name of the file to look for. @param [Array] paths An array of paths to search. @return [String]

    # File lib/ramaze/reloader.rb, line 166
    def figure_path(file, paths)
      if Pathname.new(file).absolute?
        return File.exist?(file) ? file : nil
      end

      paths.each do |possible_path|
        full_path = File.join(possible_path, file)
        return full_path if File.exist?(full_path)
      end
      nil
    end

options_reload() click to toggle source

Returns all the options for this class.

@author Michael Fellinger @since 09-08-2008 @return [Array]

    # File lib/ramaze/reloader.rb, line 85
    def options_reload
      @cooldown, @ignore, @control, @thread =
        OPTIONS.values_at(:cooldown, :ignore, :control, :thread)
    end

rotation() click to toggle source

    # File lib/ramaze/reloader.rb, line 144
    def rotation
      files = [$0, __FILE__, *$LOADED_FEATURES].uniq
      paths = ['./', *$LOAD_PATH].uniq

      files.each do |file|
        next if file =~ @ignore
        if not @files.has_key?(file) and path = figure_path(file, paths)
          @files[file] = path
          yield path
        end
      end
    end

safe_load(file) click to toggle source

A safe Kernel::load, issuing the hooks depending on the results

@author Michael Fellinger @since 09-08-2008 @param [String] file Path to the file to safely load.

    # File lib/ramaze/reloader.rb, line 135
    def safe_load(file)
      before_safe_load(file)
      load(file)
      after_safe_load_succeed(file)
    rescue Object => ex
      Log.error(ex)
      after_safe_load_failed(file, ex)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.