class Hanami::Action::Config
Config
for ‘Hanami::Action` classes.
@see Hanami::Action.config
@api public @since 2.0.0
Constants
- DEFAULT_PUBLIC_DIRECTORY
Default public directory
This serves as the root directory for file downloads
@since 1.0.0
@api private
Public Instance Methods
Sets the format (or formats) for the action.
To configure custom formats and MIME type mappings, call {Formats#add formats.add} first.
@example
config.format :html, :json
@param formats [Array<Symbol>] the format names
@return [Array<Symbol>] the given format names
@see formats
@since 2.0.0 @api public
# File lib/hanami/action/config.rb, line 84 def format(*formats) if formats.empty? self.formats.values else self.formats.values = formats end end
Specifies how to handle exceptions with an HTTP status
Raised exceptions will return the corresponding HTTP status
The specified exceptions will be merged with any previously configured exceptions
@param exceptions [Hash{Exception=>Integer}] exception classes as keys
and HTTP statuses as values
@return [void]
@example
config.handle_exceptions(ArgumentError => 400}
@see handled_exceptions
@since 0.2.0
# File lib/hanami/action/config.rb, line 54 def handle_exception(exceptions) self.handled_exceptions = handled_exceptions .merge(exceptions) .sort { |(ex1, _), (ex2, _)| ex1.ancestors.include?(ex2) ? -1 : 1 } .to_h end
@!attribute [rw] public_directory
Sets the path to public directory. This directory is used for file downloads.
This given directory will be appended onto the root directory.
By default, the public directory is ‘“public”`. @return [String] the public directory path
@example
config.public_directory = "public" config.public_directory # => "/path/to/root/public"
@see root_directory
@since 2.0.0
# File lib/hanami/action/config.rb, line 167 def public_directory # This must be a string, for Rack compatibility root_directory.join(super).to_s end