Sha256: e27b869cc302d5e9e1a7e6706f30d1a76b340986827ead52e2b1396b8375311a

Contents?: true

Size: 830 Bytes

Versions: 10

Compression:

Stored size: 830 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", File.join("config/environments", 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(', ')}"
      end
    end
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
active_generator-2.2.8 lib/generators/environment/environment_generator.rb
active_generator-2.2.7 lib/generators/environment/environment_generator.rb
active_generator-2.2.6 lib/generators/environment/environment_generator.rb
active_generator-2.2.5 lib/generators/environment/environment_generator.rb
active_generator-2.2.4 lib/generators/environment/environment_generator.rb
active_generator-2.2.3 lib/generators/environment/environment_generator.rb
active_generator-2.2.2 lib/generators/environment/environment_generator.rb
active_generator-2.2.1 lib/generators/environment/environment_generator.rb
active_generator-2.2.0 lib/generators/environment/environment_generator.rb
active_generator-2.1.0 lib/generators/environment/environment_generator.rb