Module: Elzar::ChefDNA

Defined in:
lib/elzar/chef_dna.rb

Class Method Summary collapse

Class Method Details

.gene_splice(content, database, ruby_version) ⇒ Object



3
4
5
6
# File 'lib/elzar/chef_dna.rb', line 3

def self.gene_splice(content, database, ruby_version)
  set_ruby(content, ruby_version)
  set_database(content, database)
end

.rubygems_versionObject



43
44
45
46
# File 'lib/elzar/chef_dna.rb', line 43

def self.rubygems_version
  require 'rubygems' unless defined?(Gem)
  Gem::VERSION
end

.set_database(content, database) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/elzar/chef_dna.rb', line 10

def self.set_database(content, database)
  if database == 'postgresql'
    db_index = content['run_list'].find_index { |e| (e == 'mysql::server') || (e == 'role[postgres_database]')}
    content['run_list'][db_index] = 'role[postgres_database]'
  elsif database.nil? || (database == 'mysql')
    db_index = content['run_list'].find_index { |e| (e == 'mysql::server') || (e == 'role[postgres_database]')}
    content['run_list'][db_index] = 'mysql::server'
  end
end

.set_ruby(content, ruby_version) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/elzar/chef_dna.rb', line 20

def self.set_ruby(content, ruby_version)
  if ruby_version =~ /^ree-(.*)/i
    content['ruby_enterprise']['version'] = $1
    content['ruby_enterprise']['url'] = "http://rubyenterpriseedition.googlecode.com/files/ruby-enterprise-#{$1}"
    content['ruby_enterprise']['gems_version'] = rubygems_version
    update_run_list! content['run_list'], 'role[enterprise_appstack]'
  elsif ruby_version =~ /^ruby-(.*)/i
    full_version = $1
    content['ruby']['version'] = full_version
    major_version = full_version[/(\d\.\d).*/, 1]
    content['ruby']['url'] = "http://ftp.ruby-lang.org/pub/ruby/#{major_version}/ruby-#{full_version}.tar.gz"
    content['ruby']['gems_version'] = rubygems_version
    update_run_list! content['run_list'], 'role[ruby_appstack]'
  else
    raise "Your ruby is NOT SUPPORTED. Please use ree or ruby."
  end
end

.update_run_list!(run_list, val) ⇒ Object



38
39
40
41
# File 'lib/elzar/chef_dna.rb', line 38

def self.update_run_list!(run_list, val)
  appstack_index = run_list.find_index {|e| e[/^role\[.*_appstack\]$/] }
  run_list[appstack_index] = val
end