Module: BootstrapWithSiteId

Defined in:
lib/bootstrap_with_site_id.rb

Instance Method Summary collapse

Instance Method Details

#find_template_in_path_with_site_id(filename) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/bootstrap_with_site_id.rb', line 37

def find_template_in_path_with_site_id(filename)
      [
        filename,
        "#{RAILS_ROOT}/vendor/extensions/vhost/db/templates/#{filename}",
        "#{RADIANT_ROOT}/config/extensions/vhost/db/templates/#{filename}",
        "#{RADIANT_ROOT}/#{filename}",
        "#{RADIANT_ROOT}/db/templates/#{filename}",
        "#{RAILS_ROOT}/#{filename}",
        "#{RAILS_ROOT}/db/templates/#{filename}",
        "#{Dir.pwd}/#{filename}",
        "#{Dir.pwd}/db/templates/#{filename}",
      ].find { |name| File.file?(name) }
end

#load_database_template_with_site_id(filename) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/bootstrap_with_site_id.rb', line 2

def load_database_template_with_site_id(filename)
  template = nil
  if filename
    name = find_template_in_path(filename)
    unless name
      announce "Invalid template name: #{filename}"
      filename = nil
    else
      template = load_template_file(name)
    end
  end
  unless filename
    templates = find_and_load_templates("#{RAILS_ROOT}/vendor/extensions/vhost/db/templates/*.yml")
    templates.concat find_and_load_templates("#{RADIANT_ROOT}/config/extensions/vhost/db/templates/*.yml")
    templates.concat find_and_load_templates("#{RAILS_ROOT}/db/templates/*.yml") if RADIANT_ROOT != RAILS_ROOT
    choose do |menu|
      menu.header = "\nSelect a database template"
      menu.prompt = "[1-#{templates.size}]: "
      menu.select_by = :index
      templates.each { |t| menu.choice(t['name']) { template = t } }
    end
  end
  # If there are sites defined create them first as there are many to many
  # relationships from users to sites that need to be created and will fail
  # if the site isn't created first.
  if !template['records']['Sites'].nil?
    site_template = {}
    site_template['records'] = {}
    site_template['records']['Sites'] = template['records']['Sites']
    create_records(site_template)
    site_template['records'].delete('Sites')
  end
  create_records(template)
end