lib/lotus/configuration.rb in lotusrb-0.4.1 vs lib/lotus/configuration.rb in lotusrb-0.5.0
- old
+ new
@@ -1,6 +1,7 @@
require 'lotus/utils/kernel'
+require 'lotus/utils/deprecation'
require 'lotus/environment'
require 'lotus/config/framework_configuration'
require 'lotus/config/load_paths'
require 'lotus/config/assets'
require 'lotus/config/routes'
@@ -956,53 +957,119 @@
#
# This is part of a DSL, for this reason when this method is called with
# an argument, it will set the corresponding instance variable. When
# called without, it will return the already set value, or the default.
#
- # @overload default_format(format)
+ # @overload default_request_format(format)
# Sets the given value
# @param format [#to_sym] the symbol format
# @raise [TypeError] if it cannot be coerced to a symbol
#
- # @overload default_format
+ # @overload default_request_format
# Gets the value
# @return [Symbol]
#
- # @since 0.1.0
+ # @since 0.5.0
#
- # @see http://rdoc.info/gems/lotus-controller/Lotus/Controller/Configuration#default_format
+ # @see http://rdoc.info/gems/lotus-controller/Lotus/Controller/Configuration#default_request_format
#
# @example Getting the value
# require 'lotus'
#
# module Bookshelf
# class Application < Lotus::Application
# end
# end
#
- # Bookshelf::Application.configuration.default_format # => :html
+ # Bookshelf::Application.configuration.default_request_format # => :html
#
# @example Setting the value
# require 'lotus'
#
# module Bookshelf
# class Application < Lotus::Application
# configure do
- # default_format :json
+ # default_request_format :json
# end
# end
# end
#
- # Bookshelf::Application.configuration.default_format # => :json
- def default_format(format = nil)
+ # Bookshelf::Application.configuration.default_request_format # => :json
+ def default_request_format(format = nil)
if format
- @default_format = Utils::Kernel.Symbol(format)
+ @default_request_format = Utils::Kernel.Symbol(format)
else
- @default_format || :html
+ @default_request_format || :html
end
end
+ # Set a format to be used for all responses regardless of the request type.
+ #
+ # The given format must be coercible to a symbol, and be a valid mime type
+ # alias. If it isn't, at the runtime the framework will raise a
+ # `Lotus::Controller::UnknownFormatError`.
+ #
+ # By default this value is `:html`.
+ #
+ # This is part of a DSL, for this reason when this method is called with
+ # an argument, it will set the corresponding instance variable. When
+ # called without, it will return the already set value, or the default.
+ #
+ # @overload default_response_format(format)
+ # Sets the given value
+ # @param format [#to_sym] the symbol format
+ # @raise [TypeError] if it cannot be coerced to a symbol
+ #
+ # @overload default_response_format
+ # Gets the value
+ # @return [Symbol,nil]
+ #
+ # @since 0.5.0
+ #
+ # @see http://rdoc.info/gems/lotus-controller/Lotus/Controller/Configuration#default_response_format
+ #
+ # @example Getting the value
+ # require 'lotus'
+ #
+ # module Bookshelf
+ # class Application < Lotus::Application
+ # end
+ # end
+ #
+ # Bookshelf::Application.configuration.default_response_format # => :html
+ #
+ # @example Setting the value
+ # require 'lotus'
+ #
+ # module Bookshelf
+ # class Application < Lotus::Application
+ # configure do
+ # default_response_format :json
+ # end
+ # end
+ # end
+ #
+ # Bookshelf::Application.configuration.default_response_format # => :json
+ def default_response_format(format = nil)
+ if format
+ @default_response_format = Utils::Kernel.Symbol(format)
+ else
+ @default_response_format
+ end
+ end
+
+ # Set a format as default fallback for all the requests without a strict
+ # requirement for the mime type.
+ #
+ # @since 0.1.0
+ #
+ # @deprecated Use {#default_request_format} instead.
+ def default_format(format = nil)
+ Lotus::Utils::Deprecation.new('default_format is deprecated, please use default_request_format')
+ default_request_format(format)
+ end
+
# The URI scheme for this application.
# This is used by the router helpers to generate absolute URLs.
#
# By default this value is `"http"`.
#
@@ -1575,11 +1642,11 @@
# require 'lotus'
#
# module Bookshelf
# class Application < Lotus::Application
# configure do
- # controller.default_format :json
+ # controller.default_request_format :json
# end
# end
# end
#
# @example Override a setting
@@ -1640,10 +1707,50 @@
# # It will use `:backend` layout
def view
@view ||= Config::FrameworkConfiguration.new
end
+ # Defines a logger instance to the configuration
+ #
+ # This logger instance will be used to set the logger available on application module
+ #
+ # If no logger instance is defined, a Lotus::Logger will be set by default
+ #
+ # @return [Logger, NilClass] logger instance
+ #
+ # @since 0.5.0
+ #
+ # @example Define a logger
+ # require 'lotus'
+ #
+ # module Bookshelf
+ # class Application < Lotus::Application
+ # configure do
+ # logger Logger.new(STDOUT)
+ # end
+ # load!
+ # end
+ #
+ # module Controllers::Error
+ # include Bookshelf::Controller
+ #
+ # action 'Index' do
+ # def call(params)
+ # Bookshelf::Logger.info "Logging to STDOUT"
+ # end
+ # end
+ # end
+ # end
+ #
+ def logger(value = nil)
+ if value.nil?
+ @logger
+ else
+ @logger = value
+ end
+ end
+
# This options is used as a bridge between container and router application.
#
# @return [String, NilClass] path prefix for routes
#
# @since 0.4.0
@@ -1655,9 +1762,10 @@
@path_prefix = value
end
end
private
+
# @since 0.2.0
# @api private
def evaluate_configurations!
configurations.each { |c| instance_eval(&c) }
end