lib/adhearsion/configuration.rb in adhearsion-3.0.0.beta1 vs lib/adhearsion/configuration.rb in adhearsion-3.0.0.beta2
- old
+ new
@@ -28,11 +28,11 @@
# foo "bar", :desc => "My description"
# end
#
# @return [Adhearsion::Configuration]
def initialize(env = :development, &block)
- initialize_environments env
+ @active_environment = env
Loquacious.env_config = true
Loquacious.env_prefix = "AHN"
Loquacious::Configuration.for :core do
@@ -120,34 +120,15 @@
Loquacious::Configuration.for :core, &block if block_given?
self
end
- def initialize_environments(active_environment)
- # Create a method per each valid environment that, when invoked, may execute
- # the block received if the environment is active
- valid_environments.each do |env|
- define_singleton_method env.to_sym do |*args, &block|
- logger.trace "Ignoring configuration for inactive environment #{env}"
- end
+ def env(environment)
+ if environment == @active_environment
+ yield self
+ else
+ logger.trace "Ignoring configuration for inactive environment #{environment}"
end
-
- define_singleton_method active_environment do |*args, &block|
- self.instance_eval(&block) unless block.nil?
- self
- end
-
- if valid_environment?(active_environment)
- logger.warn "You tried to initialize with an invalid environment name #{active_environment}; environment-specific config may not load successfully. Valid values are #{valid_environments}."
- end
- end
-
- def valid_environment?(env)
- env && self.valid_environments.include?(env.to_sym)
- end
-
- def valid_environments
- @valid_environments ||= [:production, :development, :staging, :test]
end
##
# Direct access to a specific configuration object
#