Sha256: 5d348b3a789b0a99a0b466aede14c49c5490a271453796e185dbad919d0b148d

Contents?: true

Size: 802 Bytes

Versions: 12

Compression:

Stored size: 802 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 copy_environment_file
    assert_valid_environment!
    template("environment.rb", "config/environments/#{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(', ')}"
      end
    end
  end

end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
active_generator-2.0.11 lib/generators/environment/environment_generator.rb
active_generator-2.0.10 lib/generators/environment/environment_generator.rb
active_generator-2.0.9 lib/generators/environment/environment_generator.rb
active_generator-2.0.8 lib/generators/environment/environment_generator.rb
active_generator-2.0.7 lib/generators/environment/environment_generator.rb
active_generator-2.0.6 lib/generators/environment/environment_generator.rb
active_generator-2.0.5 lib/generators/environment/environment_generator.rb
active_generator-2.0.4 lib/generators/environment/environment_generator.rb
active_generator-2.0.3 lib/generators/environment/environment_generator.rb
active_generator-2.0.2 lib/generators/environment/environment_generator.rb
active_generator-2.0.1 lib/generators/environment/environment_generator.rb
active_generator-2.0.0 lib/generators/environment/environment_generator.rb