Sha256: 14cb39b17c536564167255b66630dbf3e3bbd0b0d52991be7748f07fb0a7cd13

Contents?: true

Size: 1.5 KB

Versions: 3

Compression:

Stored size: 1.5 KB

Contents

module Cbac
  # Class performs various functions specific to the CBAC system itself. Most
  # important function is to check if the system is initialized; without proper
  # initialization, the bootstrapper will crash.
  class Setup
    class << self

      # Check to see if the tables are correctly migrated. If the tables are not
      # migrated, CBAC should terminate immediately.
      def check_tables
        # It is possible that there is no database connection yet. In that case, the table_exist call will fail
        begin
          return false unless Cbac::PrivilegeSetRecord.table_exists?
        rescue ActiveRecord::ConnectionNotEstablished
          puts "CBAC: Connection to database not established when initializing Cbac. Cbac is *not* running."
          return false
        end
        return false unless Cbac::GenericRole.table_exists?
        return false unless Cbac::Membership.table_exists?
        return false unless Cbac::Permission.table_exists?
        true
      end

      # Checks if the system is properly setup. This method is used by the
      # bootstrapper to see if the system should be initialized. If the system
      # is not properly setup, the bootstrapper will crash. Checks are performed
      # to see if all the tables exists.
      def check
        if check_tables == false
          puts "CBAC: not properly initialized: one or more tables are missing. Did you install it correctly? (run generate)"
          return false
        end
        true
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cbac-0.6.5 lib/cbac/setup.rb
cbac-0.6.4 lib/cbac/setup.rb
cbac-0.6.2 lib/cbac/setup.rb