Sha256: 8dc35b594a23e9381f892e4460ef728948638d47a7a4f8c9fec8cb1511af4cf8

Contents?: true

Size: 1.83 KB

Versions: 5

Compression:

Stored size: 1.83 KB

Contents

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

    private

    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

    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

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

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
elzar-0.1.2 lib/elzar/chef_dna.rb
elzar-0.1.1 lib/elzar/chef_dna.rb
elzar-0.1.0 lib/elzar/chef_dna.rb
elzar-0.0.2 lib/elzar/chef_dna.rb
elzar-0.0.1 lib/elzar/chef_dna.rb