Sha256: 6cecb937877b67179aaeb2db19451180390e1e9703cc5a271ded30ff47710590

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

require "rails/generators"

module Multiverse
  module Generators
    class DbGenerator < Rails::Generators::Base
      source_root File.expand_path("../templates", __FILE__)

      argument :name

      def create_initializer
        lower_name = name.underscore

        template "record.rb", "app/models/#{lower_name}_record.rb"

        case ActiveRecord::Base.connection_config[:adapter]
        when "sqlite3"
          development_conf = "database: db/#{lower_name}_development.sqlite3"
          test_conf = "database: db/#{lower_name}_test.sqlite3"
          production_conf = "database: db/#{lower_name}_production.sqlite3"
        else
          development_conf = "database: #{lower_name}_development"
          test_conf = "database: #{lower_name}_development"
          production_conf = "url: <%= ENV['#{lower_name.upcase}_DATABASE_URL'] %>"
        end

        append_to_file "config/database.yml" do
          "
#{name}_development:
  <<: *default
  #{development_conf}

#{name}_test:
  <<: *default
  #{test_conf}

#{name}_production:
  <<: *default
  #{production_conf}
"
        end

        empty_directory "db/#{lower_name}/migrate"
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
multiverse-0.0.3 lib/generators/multiverse/db_generator.rb
multiverse-0.0.2 lib/generators/multiverse/db_generator.rb