Class: Hanami::Action::Config
- Inherits:
-
Dry::Configurable::Config
- Object
- Dry::Configurable::Config
- Hanami::Action::Config
- Defined in:
- lib/hanami/action/config.rb,
lib/hanami/action/config/formats.rb
Overview
Config for ‘Hanami::Action` classes.
Defined Under Namespace
Classes: Formats
Constant Summary collapse
- DEFAULT_PUBLIC_DIRECTORY =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Default public directory
This serves as the root directory for file downloads
"public"
Instance Attribute Summary collapse
-
#cookies ⇒ Hash{Symbol=>String}
Sets default cookie options for all responses.
-
#default_charset ⇒ String
Sets a charset (character set) as default fallback for all the requests without a strict requirement for the charset.
-
#default_headers ⇒ Hash{String=>String}
Sets default headers for all responses.
-
#default_tld_length ⇒ Integer
Sets the default TLD length for host names.
-
#formats ⇒ Config::Formats
readonly
Returns the format config for the action.
-
#handled_exceptions ⇒ Hash{Exception=>Integer}
Specifies how to handle exceptions with an HTTP status.
-
#public_directory ⇒ String
Sets the path to public directory.
-
#root_directory ⇒ String
private
Sets the the for the public directory, which is used for file downloads.
Instance Method Summary collapse
-
#format(*formats) ⇒ Array<Symbol>
Sets the format (or formats) for the action.
-
#handle_exception(exceptions) ⇒ void
Specifies how to handle exceptions with an HTTP status.
Instance Attribute Details
#cookies ⇒ Hash{Symbol=>String}
Sets default cookie options for all responses.
By default this, is an empty hash.
|
|
# File 'lib/hanami/action/config.rb', line 153
|
#default_charset ⇒ String
Sets a charset (character set) as default fallback for all the requests without a strict requirement for the charset.
By default, this value is nil.
|
|
# File 'lib/hanami/action/config.rb', line 107
|
#default_headers ⇒ Hash{String=>String}
Sets default headers for all responses.
By default, this is an empty hash.
|
|
# File 'lib/hanami/action/config.rb', line 120
|
#default_tld_length ⇒ Integer
Sets the default TLD length for host names. It is used to extract the subdomain(s) in ‘Request#subdomains`.
Defaults to 1.
|
|
# File 'lib/hanami/action/config.rb', line 135
|
#formats ⇒ Config::Formats (readonly)
Returns the format config for the action.
|
|
# File 'lib/hanami/action/config.rb', line 65
|
#handled_exceptions ⇒ Hash{Exception=>Integer}
Specifies how to handle exceptions with an HTTP status.
Raised exceptions will return the corresponding HTTP status.
|
|
# File 'lib/hanami/action/config.rb', line 23
|
#public_directory ⇒ String
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”`.
200 201 202 203 |
# File 'lib/hanami/action/config.rb', line 200 def public_directory # This must be a string, for Rack compatibility root_directory.join(super).to_s end |
#root_directory ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Sets the the for the public directory, which is used for file downloads. This must be an existent directory.
Defaults to the current working directory.
|
|
# File 'lib/hanami/action/config.rb', line 171
|
Instance Method Details
#format(*formats) ⇒ Array<Symbol>
Sets the format (or formats) for the action.
To configure custom formats and MIME type mappings, call formats.register first.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/hanami/action/config.rb', line 89 def format(*formats) msg = " Hanami::Action `config.format` is deprecated and will be removed in Hanami 2.4.\n\n Please use `config.formats.register` and/or `config.formats.accept` instead.\n\n See https://guides.hanamirb.org/v2.3/actions/formats-and-mime-types/ for details.\n TEXT\n warn(msg, category: :deprecated)\n\n if formats.empty?\n self.formats.values\n else\n self.formats.values = formats\n self.formats.default = formats.first\n end\nend\n" |
#handle_exception(exceptions) ⇒ void
This method returns an undefined value.
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
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/hanami/action/config.rb', line 54 def handle_exception(exceptions) self.handled_exceptions = handled_exceptions .merge(exceptions) .sort do |(ex1, _), (ex2, _)| next 0 if [ex1, ex2].any?(String) ex1.ancestors.include?(ex2) ? -1 : 1 end .to_h end |