Sha256: bb00b0af135bebf0b3aa7dcb955fd13245dfae725983df7bc29e29966f5d6c2c

Contents?: true

Size: 1.53 KB

Versions: 135

Compression:

Stored size: 1.53 KB

Contents

class Jets::Turbo
  class DatabaseYaml
    def reconfigure
      current_yaml = "#{Jets.root}/rack/config/database.yml"
      return unless File.exist?(current_yaml)

      vars = {}
      current_database = YAML.load_file(current_yaml)
      database_names = infer_database_name(current_database)
      vars.merge!(database_names)
      vars['adapter'] = current_database['development']['adapter']

      path = File.expand_path("templates/config/database.yml", File.dirname(__FILE__))
      content = Jets::Erb.result(path, vars)
      IO.write(current_yaml, content)
      # puts "Reconfigured #{current_yaml}" # uncomment to inspect and debug
    rescue Exception => e
      puts "WARNING: Was not able to generate a database.yml. Leaving your current one in place"
      puts e.message
      # If unable to copy the database.yml settings just slightly fail.
      # Do this because really unsure what is in the current database.yml
    end

    def infer_database_name(current_database)
      vars = {}
      %w[development test production].each do |env|
        if !current_database[env]['database'].include?('<%') # already has ERB
          vars["database_#{env}"] = current_database[env]['database']
        else
          lines = IO.readlines("#{Jets.root}/rack/config/application.rb")
          module_line = lines.find { |l| l =~ /^module / }
          app_module = module_line.gsub(/^module /,'').strip
          app_name = app_module.underscore
          vars["database_#{env}"] = "#{app_name}_#{env}"
        end
      end

      vars
    end
  end
end

Version data entries

135 entries across 135 versions & 4 rubygems

Version Path
jets-3.2.2 lib/jets/turbo/database_yaml.rb
jets-3.2.1 lib/jets/turbo/database_yaml.rb
jets.benforeva-3.0.17.pre.mount.pre.fix lib/jets/turbo/database_yaml.rb
jets-3.2.0 lib/jets/turbo/database_yaml.rb
jets-3.1.5 lib/jets/turbo/database_yaml.rb
jets-3.1.4 lib/jets/turbo/database_yaml.rb
jets-3.1.3 lib/jets/turbo/database_yaml.rb
jets-3.1.2 lib/jets/turbo/database_yaml.rb
jets-3.1.1 lib/jets/turbo/database_yaml.rb
jets-3.1.0 lib/jets/turbo/database_yaml.rb
jets-3.0.23 lib/jets/turbo/database_yaml.rb
jets-3.0.22 lib/jets/turbo/database_yaml.rb
jets-3.0.21 lib/jets/turbo/database_yaml.rb
jets-3.0.20 lib/jets/turbo/database_yaml.rb
jets-3.0.19 lib/jets/turbo/database_yaml.rb
jets-3.0.18 lib/jets/turbo/database_yaml.rb
jets-3.0.17 lib/jets/turbo/database_yaml.rb
jets-3.0.16 lib/jets/turbo/database_yaml.rb
jets-3.0.15 lib/jets/turbo/database_yaml.rb
jets-3.0.14 lib/jets/turbo/database_yaml.rb