Sha256: 9d26d252b41f15385e7429f10e7b8f6da9ba19abb46a5400d8da385f094e4ab3

Contents?: true

Size: 1.08 KB

Versions: 4

Compression:

Stored size: 1.08 KB

Contents

class Recipes::Database < Rails::AppBuilder
  def ask
    databases = {
      postgresql: "PostgreSQL",
      mysql: "MySQL",
      none: "None, thanks"
    }

    database = answer(:db) do
      databases.keys[Ask.list("Which database are you using?", databases.values)]
    end

    set :database, database.to_sym
  end

  def create
    if db = databases(get(:database))
      if db[:relational]
        activate_for_active_record(db)
      end
    end
  end

  def install
    ask
    create
  end

  private

  def databases(database)
    databases = {
      postgresql: { name: 'postgresql', gem_name: 'pg', relational: true },
      mysql: { name: 'mysql', gem_name: 'mysql2', version: '~> 0.5.0', relational: true }
    }
    databases[database]
  end

  def activate_for_active_record(db)
    remove_file 'config/database.yml'
    template "../assets/config/database_#{db[:name]}.yml.erb", 'config/database.yml'
    discard_gem 'sqlite3'
    gather_gem 'strong_migrations'
    if db[:version]
      gather_gem db[:gem_name], db[:version]
    else
      gather_gem db[:gem_name]
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
potassium-6.0.0 lib/potassium/recipes/database.rb
potassium-5.2.3 lib/potassium/recipes/database.rb
potassium-5.2.2 lib/potassium/recipes/database.rb
potassium-5.2.1 lib/potassium/recipes/database.rb