lib/hanami/controller/configuration.rb in hanami-controller-0.8.1 vs lib/hanami/controller/configuration.rb in hanami-controller-1.0.0.beta1

- old
+ new

@@ -24,10 +24,18 @@ # # @since 0.2.0 # @api private DEFAULT_ERROR_CODE = 500 + # Default public directory + # + # It serves as base root for file downloads + # + # @since 1.0.0.beta1 + # @api private + DEFAULT_PUBLIC_DIRECTORY = 'public'.freeze + # Default Mime type to format mapping # # @since 0.2.0 # @api private DEFAULT_FORMATS = { @@ -210,11 +218,11 @@ # Finds configured handler for given exception, or nil if not found. # # @param exception [Exception] an exception # - # @since x.x.x + # @since 1.0.0.beta1 # @api private # # @see Hanami::Controller::Configuration#handle_exception def exception_handler_for(exception) @handled_exceptions.each do |exception_class, handler| @@ -421,14 +429,26 @@ # @see Hanami::Controller::Configuration#format # @see Hanami::Action::Mime::MIME_TYPES def mime_types @mime_types ||= begin ((@formats.keys - DEFAULT_FORMATS.keys) + - ::Rack::Mime::MIME_TYPES.values).freeze + Hanami::Action::Mime::MIME_TYPES.values).freeze end end + # Restrict the MIME types set only to the given set + # + # @param mime_types [Array] the set of MIME types + # + # @since 1.0.0.beta1 + # @api private + # + # @see Hanami::Action::Mime::ClassMethods#accept + def restrict_mime_types!(mime_types) + @mime_types = self.mime_types & mime_types + end + # Set a format as default fallback for all the requests without a strict # requirement for the mime 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 @@ -629,10 +649,18 @@ # @api private def mime_type_for(format) @formats.key(format) end + def public_directory(value = nil) + if value.nil? + @public_directory + else + @public_directory = Pathname.new(Dir.pwd).join(value).to_s + end + end + # Duplicate by copying the settings in a new instance. # # @return [Hanami::Controller::Configuration] a copy of the configuration # # @since 0.2.0 @@ -646,10 +674,11 @@ c.formats = formats.dup c.default_request_format = default_request_format c.default_response_format = default_response_format c.default_charset = default_charset c.default_headers = default_headers.dup + c.public_directory = public_directory c.cookies = cookies.dup end end # Return included modules @@ -675,10 +704,11 @@ @default_request_format = nil @default_response_format = nil @default_charset = nil @default_headers = {} @cookies = {} + @public_directory = ::File.join(Dir.pwd, "public") @action_module = ::Hanami::Action end # Copy the configuration for the given action # @@ -720,8 +750,9 @@ attr_writer :default_request_format attr_writer :default_response_format attr_writer :default_charset attr_writer :default_headers attr_writer :cookies + attr_writer :public_directory end end end