Class: Lockdown::Database

Inherits:
Object
  • Object
show all
Defined in:
lib/lockdown/database.rb

Class Method Summary collapse

Class Method Details

.create_user_group(name_str, key) ⇒ Object



34
35
36
37
# File 'lib/lockdown/database.rb', line 34

def create_user_group(name_str, key)
  Lockdown.logger.info ">> Lockdown: #{Lockdown::System.fetch(:user_group_model)} not in the db: #{name_str}, creating."
  ug = Lockdown.user_group_class.create(:name => name_str)
end

.maintain_user_groupsObject



24
25
26
27
28
29
30
31
32
# File 'lib/lockdown/database.rb', line 24

def maintain_user_groups
  # Create user groups not found in the database
  @user_groups.each do |key|
    str = Lockdown.get_string(key)
    unless ug = Lockdown.user_group_class.find(:first, :conditions => ["name = ?", str])
      create_user_group(str, key)
    end
  end
end

.sync_with_dbObject

This is very basic and could be handled better using orm specific functionality, but I wanted to keep it generic to avoid creating an interface for each the different orm implementations. We’ll see how it works…



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/lockdown/database.rb', line 8

def sync_with_db

  @permissions = Lockdown::System.get_permissions
  @user_groups = Lockdown::System.get_user_groups

  unless Lockdown.user_group_class.table_exists?
    Lockdown.logger.info ">> Lockdown tables not found.  Skipping database sync."
    return
  end

  maintain_user_groups
rescue Exception => e
  Lockdown.logger.error ">> Lockdown sync failed: #{e.backtrace.join("\n")}" 
end