### Home Classes Methods

### In Files

- lib/amalgalite/requires.rb

### Parent

Object

### Methods

- ::db_connection_to
- ::load_path
- ::load_path_db_connections
- ::new
- ::require
- ::requiring
- #require
- #sql

### Files

- HISTORY.rdoc
- LICENSE
- README.rdoc

### Class/Module Index

Quicksearch

- Amalgalite
- Amalgalite::Aggregate
- Amalgalite::Blob
- Amalgalite::Blob::Error
- Amalgalite::Boolean
- Amalgalite::BusyHandler
- Amalgalite::BusyTimeout
- Amalgalite::CSVTableImporter
- Amalgalite::Column
- Amalgalite::Database
- Amalgalite::Database::AggregateError
- Amalgalite::Database::BusyHandlerError
- Amalgalite::Database::FunctionError
- Amalgalite::Database::InvalidModeError
- Amalgalite::Database::ProgressHandlerError
- Amalgalite::Database::TransactionBehavior
- Amalgalite::Error
- Amalgalite::Function
- Amalgalite::Index
- Amalgalite::MemoryDatabase
- Amalgalite::Packer
- Amalgalite::Paths
- Amalgalite::ProfileSampler
- Amalgalite::ProfileTap
- Amalgalite::ProgressHandler
- Amalgalite::Requires
- Amalgalite::SQLite3
- Amalgalite::SQLite3::Constants
- Amalgalite::SQLite3::Constants::Config
- Amalgalite::SQLite3::Constants::DBStatus
- Amalgalite::SQLite3::Constants::DataType
- Amalgalite::SQLite3::Constants::Helpers
- Amalgalite::SQLite3::Constants::Open
- Amalgalite::SQLite3::Constants::ResultCode
- Amalgalite::SQLite3::Constants::StatementStatus
- Amalgalite::SQLite3::Constants::Status
- Amalgalite::SQLite3::Database
- Amalgalite::SQLite3::Database::DBStatus
- Amalgalite::SQLite3::Database::Function
- Amalgalite::SQLite3::Database::Stat
- Amalgalite::SQLite3::Stat
- Amalgalite::SQLite3::Status
- Amalgalite::SQLite3::Version
- Amalgalite::Schema
- Amalgalite::Statement
- Amalgalite::Table
- Amalgalite::Taps
- Amalgalite::Taps::IO
- Amalgalite::Taps::Stderr
- Amalgalite::Taps::Stdout
- Amalgalite::Taps::StringIO
- Amalgalite::TraceTap
- Amalgalite::TypeMap
- Amalgalite::TypeMaps
- Amalgalite::TypeMaps::DefaultMap
- Amalgalite::TypeMaps::StorageMap
- Amalgalite::TypeMaps::TextMap
- Amalgalite::Version
- Amalgalite::View
- Kernel
- Object

No matching classes.

# Amalgalite::Requires

Requires encapsulates requiring items from the database

### Attributes

compressed_column[R]
contents_column[R]
db_connection[R]
dbfile_name[R]
filename_column[R]
table_name[R]

### Public Class Methods

db_connection_to( dbfile_name ) click to toggle source

Allocate a database connection to the given filename

    # File lib/amalgalite/requires.rb, line 23
    def db_connection_to( dbfile_name )
      unless connection = load_path_db_connections[ dbfile_name ]
        connection = ::Amalgalite::Database.new( dbfile_name )
        load_path_db_connections[dbfile_name] = connection
      end
      return connection
    end

load_path() click to toggle source

    # File lib/amalgalite/requires.rb, line 16
    def load_path
      @load_path ||= []
    end

load_path_db_connections() click to toggle source

    # File lib/amalgalite/requires.rb, line 12
    def load_path_db_connections
      @load_path_db_connections ||= {}
    end

new( opts = {} ) click to toggle source

    # File lib/amalgalite/requires.rb, line 67
    def initialize( opts = {} )
      @dbfile_name       = opts[:dbfile_name]       || Bootstrap::DEFAULT_DB
      @table_name        = opts[:table_name]        || Bootstrap::DEFAULT_TABLE
      @filename_column   = opts[:filename_column]   || Bootstrap::DEFAULT_FILENAME_COLUMN
      @contents_column   = opts[:contents_column]   || Bootstrap::DEFAULT_CONTENTS_COLUMN
      @compressed_column = opts[:compressed_column] || Bootstrap::DEFAULT_COMPRESSED_COLUMN
      @db_connection   = Requires.db_connection_to( dbfile_name )
      Requires.load_path << self
    end

require( filename ) click to toggle source

    # File lib/amalgalite/requires.rb, line 39
    def require( filename )
      if load_path.empty? then
        raise ::LoadError, "Amalgalite load path is empty -- #{filename}"
      elsif $LOADED_FEATURES.include?( filename ) then
        return false
      elsif Requires.requiring.include?( filename ) then
        return false
      else
        Requires.requiring << filename
        load_path.each do |lp|
          if lp.require( filename ) then
            Requires.requiring.delete( filename )
            return true
          end
        end
        Requires.requiring.delete( filename )
        raise ::LoadError, "amalgalite has no such file to load -- #{filename}"
      end
    end

requiring() click to toggle source

Setting a class level variable as a flag to know what we are currently in the middle of requiring

    # File lib/amalgalite/requires.rb, line 35
    def requiring
      @requiring ||= []
    end

### Public Instance Methods

require( filename ) click to toggle source

load a file in this database table. This will check and see if the file is already required. If it isn't it will select the contents associated with the row identified by the filename and eval those contents within the context of TOPLEVEL_BINDING. The filename is then appended to $LOADED_FEATURES.

if the file was required then true is returned, otherwise false

    # File lib/amalgalite/requires.rb, line 93
    def require( filename )
      if $LOADED_FEATURES.include?( filename ) then
        return false
      else
        begin
          filename = filename.gsub(/\.rb\Z/,'')
          rows = db_connection.execute(sql, filename)
          if rows.size > 0 then
            row = rows.first
            contents = row[contents_column].to_s
            if row[compressed_column] then
              contents = ::Amalgalite::Packer.gunzip( contents )
            end

            eval( contents, TOPLEVEL_BINDING, row[filename_column] )
            $LOADED_FEATURES << row[filename_column]
            return true
          else
            return false
          end
        rescue => e
          raise ::LoadError, "Failure loading #{filename} from #{dbfile_name} : #{e}"
        end
      end
    end

sql() click to toggle source

return the sql to find the file contents for a file in this requires

    # File lib/amalgalite/requires.rb, line 80
    def sql
      @sql ||= "SELECT #{filename_column}, #{compressed_column}, #{contents_column} FROM #{table_name} WHERE #{filename_column} = ?"
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.