Sha256: 0d7a19bdd81f06e7f16595de0cd1f65df70e31d2cec88cc69747778ee9b6aeeb

Contents?: true

Size: 1.76 KB

Versions: 28

Compression:

Stored size: 1.76 KB

Contents

require 'amalgalite3'
require 'amalgalite/sqlite3/constants'
module Amalgalite::SQLite3
  class Database
    # 
    # A Stat represents a single Database Status code and its current highwater mark.
    #
    # Some stats may not have a current or a highwater value, in those cases
    # the associated _has_current?_ or _has_highwater?_ method returns false and the
    # _current_ or _highwater_ method also returns +nil+.
    #
    class Stat
      attr_reader :name
      attr_reader :code

      def initialize( api_db, name )
        @name      = name
        @code      = ::Amalgalite::SQLite3::Constants::DBStatus.value_from_name( name )
        @current   = nil
        @highwater = nil
        @api_db    = api_db 
      end

      def current
        update!
        return @current
      end

      def highwater
        update!
        return @highwater
      end

      #
      # reset the given stat's highwater mark.  This will also populate the
      # _@current_ and _@highwater_ instance variables
      #
      def reset!
        update!( true )
      end
    end

    #
    # Top level Status object holding all the Stat objects indicating the DBStatus
    # of the SQLite3 C library.
    #
    class DBStatus
      ::Amalgalite::SQLite3::Constants::DBStatus.constants.each do |const_name|
        method_name = const_name.downcase
        module_eval( <<-code, __FILE__, __LINE__ )
        def #{method_name}
          @#{method_name} ||=  Amalgalite::SQLite3::Database::Stat.new( self.api_db, '#{method_name}' )   
        end
      code
      end

      attr_reader :api_db

      def initialize( api_db )
        @api_db = api_db
      end
    end

    # return the DBstatus object for the sqlite database
    def status
      @status ||= DBStatus.new( self )
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
amalgalite-0.4.0 lib/amalgalite/sqlite3/database/status.rb
amalgalite-0.4.2 lib/amalgalite/sqlite3/database/status.rb
amalgalite-0.5.0-x86-mswin32-60 lib/amalgalite/sqlite3/database/status.rb
amalgalite-0.4.2-x86-mswin32-60 lib/amalgalite/sqlite3/database/status.rb
amalgalite-0.4.1 lib/amalgalite/sqlite3/database/status.rb
amalgalite-0.5.0 lib/amalgalite/sqlite3/database/status.rb
amalgalite-0.5.1-x86-mswin32-60 lib/amalgalite/sqlite3/database/status.rb
amalgalite-0.5.1 lib/amalgalite/sqlite3/database/status.rb
amalgalite-0.6.0 lib/amalgalite/sqlite3/database/status.rb
amalgalite-0.7.0 lib/amalgalite/sqlite3/database/status.rb
amalgalite-0.6.0-x86-mswin32-60 lib/amalgalite/sqlite3/database/status.rb
amalgalite-0.7.0-x86-mswin32-60 lib/amalgalite/sqlite3/database/status.rb
amalgalite-0.7.3-x86-mswin32-60 lib/amalgalite/sqlite3/database/status.rb
amalgalite-0.7.1 lib/amalgalite/sqlite3/database/status.rb
amalgalite-0.7.3 lib/amalgalite/sqlite3/database/status.rb
amalgalite-0.7.1-x86-mswin32-60 lib/amalgalite/sqlite3/database/status.rb
amalgalite-0.7.4-x86-mswin32-60 lib/amalgalite/sqlite3/database/status.rb
amalgalite-0.7.4 lib/amalgalite/sqlite3/database/status.rb
amalgalite-0.7.5-x86-mswin32-60 lib/amalgalite/sqlite3/database/status.rb
amalgalite-0.7.5 lib/amalgalite/sqlite3/database/status.rb