Class: Cbac::Setup

Inherits:
Object
  • Object
show all
Defined in:
lib/cbac/setup.rb

Overview

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 Method Summary collapse

Class Method Details

.checkObject

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.



28
29
30
31
32
33
34
35
# File 'lib/cbac/setup.rb', line 28

def check
  unless check_tables
    puts "CBAC: not properly initialized: one or more tables are missing. Did you install it correctly? (run generate)"
    return false
  end

  return true
end

.check_tablesObject

Check to see if the tables are correctly migrated. If the tables are not migrated, CBAC should terminate immediately.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/cbac/setup.rb', line 11

def check_tables
  begin
    classes = [ Cbac::PrivilegeSetRecord, Cbac::GenericRole, Cbac::Membership, Cbac::Permission ]
    return classes.all? do |c|
      c.table_exists?
    end
  rescue ActiveRecord::ConnectionNotEstablished
    # There is no database connection yet.
    puts "CBAC: Connection to database not established when initializing Cbac. Cbac is *not* running."
    return false
  end
end