lib/lita/default_configuration.rb in lita-4.0.0.rc1 vs lib/lita/default_configuration.rb in lita-4.0.0.rc2
- old
+ new
@@ -8,31 +8,30 @@
# A {Registry} to extract configuration for plugins from.
# @return [Lita::Registry] The registry.
attr_reader :registry
- # The top-level {Configuration} attribute.
+ # The top-level {Lita::ConfigurationBuilder} attribute.
# @return [Lita::Configuration] The root attribute.
attr_reader :root
# @param registry [Lita::Registry] The registry to build a default configuration object from.
def initialize(registry)
@registry = registry
- @root = Configuration.new
+ @root = ConfigurationBuilder.new
adapters_config
handlers_config
http_config
redis_config
robot_config
end
- # Processes the {Configuration} object to return a raw object with only the appropriate methods.
- # This is the value that's actually stored in {Lita::Registry#config}.
- # @return [Object] The final form of the configuration object.
- def finalize
- final_config = root.finalize
+ # Processes the {Lita::ConfigurationBuilder} object to return a {Lita:Configuration}.
+ # @return [Lita::Configuration] The built configuration object.
+ def build
+ final_config = root.build
add_adapter_attribute(final_config)
add_struct_access_to_redis(final_config.redis)
final_config
end
@@ -42,11 +41,11 @@
def adapters_config
adapters = registry.adapters
root.config :adapters do
adapters.each do |key, adapter|
- combine(key, adapter.configuration)
+ combine(key, adapter.configuration_builder)
end
end
end
# Builds config.adapter
@@ -95,12 +94,12 @@
def handlers_config
handlers = registry.handlers
root.config :handlers do
handlers.each do |handler|
- if handler.configuration.children?
- combine(handler.namespace, handler.configuration)
+ if handler.configuration_builder.children?
+ combine(handler.namespace, handler.configuration_builder)
else
old_config = Config.new
handler.default_config(old_config) if handler.respond_to?(:default_config)
config(handler.namespace, default: old_config)
end
@@ -110,13 +109,13 @@
# Builds config.http
def http_config
root.config :http do
config :host, type: String, default: "0.0.0.0"
- config :port, type: Integer, default: 8080
- config :min_threads, type: Integer, default: 0
- config :max_threads, type: Integer, default: 16
+ config :port, type: [Integer, String], default: 8080
+ config :min_threads, type: [Integer, String], default: 0
+ config :max_threads, type: [Integer, String], default: 16
config :middleware, type: Array, default: []
end
end
# Builds config.redis
@@ -133,10 +132,10 @@
config :adapter, types: [String, Symbol], default: :shell
config :locale, types: [String, Symbol], default: I18n.locale
config :log_level, types: [String, Symbol], default: :info do
validate do |value|
unless LOG_LEVELS.include?(value.to_s.downcase.strip)
- "log_level must be one of: #{LOG_LEVELS.join(", ")}"
+ "must be one of: #{LOG_LEVELS.join(", ")}"
end
end
end
config :admins
end