Sha256: dfef6b1ac69b7d51a551a6eb87e1ace01d24f42a3728e384037715836da1f8f5

Contents?: true

Size: 849 Bytes

Versions: 1

Compression:

Stored size: 849 Bytes

Contents

class EnvironmentGenerator < Rails::Generators::NamedBase
  source_root File.expand_path('../templates', __FILE__)
  argument :environment, type: :string, required: false, default: nil, desc: 'The environment template to copy'

  def create_environment_file
    assert_valid_environment!
    template('environment.rb'.freeze, File.join('config/environments'.freeze, class_path, "#{file_name}.rb"))
  end

  private

  ENVIRONMENTS = %w(development test production)

  ENVIRONMENTS.each do |env|
    define_method("#{env}?") { environment == env }
  end

  def assert_valid_environment!
    unless environment.nil?
      unless ENVIRONMENTS.include?(environment)
        raise ArgumentError,
          "Unknown environment: #{environment.inspect}. Valid environments are: #{ENVIRONMENTS.map(&:inspect).join(', '.freeze)}"
      end
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_generator-2.3.0 lib/generators/environment/environment_generator.rb