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.
-
#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 120
|
#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 92
|
#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 105
|
#formats ⇒ Config::Formats (readonly)
Returns the format config for the action.
|
# File 'lib/hanami/action/config.rb', line 61
|
#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”`.
167 168 169 170 |
# 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 |
#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 138
|
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.add first.
84 85 86 87 88 89 90 |
# File 'lib/hanami/action/config.rb', line 84 def format(*formats) if formats.empty? self.formats.values else self.formats.values = formats end end |
#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 |
# 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 |