Module: Padrino::Loader

### Home Classes Methods

### In Files

- lib/padrino-core/loader.rb

### Methods

- #after_load
- #before_load
- #called_from
- #clear!
- #dependency_paths
- #load!
- #load_paths
- #loaded?
- #reload!
- #require_dependencies
- #set_load_paths

### 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::Loader

### Public Instance Methods

after_load(&block) click to toggle source

Hooks to be called after a load/reload.

@yield []

    The given block will be called after Padrino was loaded/reloaded.

@return [Array<Proc>]

    The load/reload hooks.

@example

    after_load do
      DataMapper.finalize
    end

    # File lib/padrino-core/loader.rb, line 37
    def after_load(&block)
      @_after_load ||= []
      @_after_load << block if block_given?
      @_after_load
    end

before_load(&block) click to toggle source

Hooks to be called before a load/reload.

@yield []

    The given block will be called before Padrino was loaded/reloaded.

@return [Array<Proc>]

    The load/reload before hooks.

@example

    before_load do
      pre_initialize_something
    end

    # File lib/padrino-core/loader.rb, line 17
    def before_load(&block)
      @_before_load ||= []
      @_before_load << block if block_given?
      @_before_load
    end

called_from() click to toggle source

This adds the ability to instantiate {Padrino.load!} after {Padrino::Application} definition.

    # File lib/padrino-core/loader.rb, line 94
    def called_from
      @_called_from || first_caller
    end

clear!() click to toggle source

Clear the padrino env.

@return [NilClass]

    # File lib/padrino-core/loader.rb, line 69
    def clear!
      clear_middleware!
      mounted_apps.clear
      @_dependency_paths = nil
      before_load.clear
      after_load.clear
      global_configurations.clear
      Reloader.clear!
      Thread.current[:padrino_loaded] = nil
    end

dependency_paths() click to toggle source

Returns default list of path globs to load as dependencies. Appends custom dependency patterns to the be loaded for Padrino.

@return [Array<String>]

    The dependencey paths.

@example

    Padrino.dependency_paths << "#{Padrino.root}/uploaders/*.rb"

    # File lib/padrino-core/loader.rb, line 169
    def dependency_paths
      @_dependency_paths ||= default_dependency_paths + modules_dependency_paths
    end

load!() click to toggle source

Requires necessary dependencies as well as application files from root lib and models.

@return [Boolean]

    returns true if Padrino is not already bootstraped otherwise else.

    # File lib/padrino-core/loader.rb, line 50
    def load!
      return false if loaded?
      began_at = Time.now
      @_called_from = first_caller
      set_encoding
      Padrino.logger
      Reloader.lock!
      before_load.each(&:call)
      require_dependencies(*dependency_paths)
      after_load.each(&:call)
      logger.devel "Loaded Padrino in #{Time.now - began_at} seconds"
      Thread.current[:padrino_loaded] = true
    end

load_paths() click to toggle source

Deprecated

    # File lib/padrino-core/loader.rb, line 180
    def load_paths
      warn 'Padrino.load_paths is deprecated. Please, use Padrino::Application#prerequisites'
      []
    end

loaded?() click to toggle source

Determines whether Padrino was loaded with {Padrino.load!}.

@return [Boolean]

    Specifies whether Padrino was loaded.

    # File lib/padrino-core/loader.rb, line 104
    def loaded?
      Thread.current[:padrino_loaded]
    end

reload!() click to toggle source

Method for reloading required applications and their files.

    # File lib/padrino-core/loader.rb, line 83
    def reload!
      return unless Reloader.changed?
      before_load.each(&:call)
      Reloader.reload!
      after_load.each(&:call)
    end

require_dependencies(*paths) click to toggle source

Attempts to require all dependency libs that we need. If you use this method we can perform correctly a Padrino.reload! Another good thing that this method are dependency check, for example:

    # models
    #  \-- a.rb => require something of b.rb
    #  \-- b.rb

In the example above if we do:

    Dir["/models/*.rb"].each { |r| require r }

We get an error, because we try to require first `a.rb` that need something of `b.rb`.

With this method we don't have this problem.

@param [Array<String>] paths

    The paths to require.

@example For require all our app libs we need to do:

    require_dependencies("#{Padrino.root}/lib/**/*.rb")

    # File lib/padrino-core/loader.rb, line 132
    def require_dependencies(*paths)
      options = paths.extract_options!.merge( :cyclic => true )
      files = paths.flatten.flat_map{ |path| Dir.glob(path).sort_by{ |filename| filename.count('/') } }.uniq

      until files.empty?
        error = fatal = loaded = nil

        files.dup.each do |file|
          begin
            Reloader.safe_load(file, options)
            files.delete(file)
            loaded = true
          rescue NameError, LoadError => error
            logger.devel "Cyclic dependency reload for #{error.class}: #{error.message}"
          rescue Exception => fatal
            break
          end
        end

        if fatal || !loaded
          exception = fatal || error
          logger.exception exception, :short
          raise exception
        end
      end
    end

set_load_paths(*) click to toggle source

Deprecated

    # File lib/padrino-core/loader.rb, line 174
    def set_load_paths(*)
      warn 'Padrino.set_load_paths is deprecated. Please, use $LOAD_PATH.concat(paths)'
      []
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.