Class: SimpleImagesDownloader::Configuration
- Inherits:
-
Object
- Object
- SimpleImagesDownloader::Configuration
- Includes:
- Singleton
- Defined in:
- lib/simple_images_downloader/configuration.rb
Overview
Configuration class
Constant Summary collapse
- ACCESSORS =
%i[ destination valid_mime_types ].freeze
- REQUEST_OPTIONS =
{ 'User-Agent' => "SimpleImagesDownloader/#{SimpleImagesDownloader::VERSION}", redirect: false, open_timeout: 30, read_timeout: 30 }.freeze
- DEFAULT_VALID_MIME_TYPES =
[ 'image/avif', 'image/gif', 'image/apng', 'image/jpg', 'image/jpeg', 'image/png', 'image/svg+xml', 'image/webp' ].freeze
- DEFAULT_DESTINATION =
'./'
Class Method Summary collapse
- .accessor?(method) ⇒ Boolean
-
.configure {|config| ... } ⇒ Object
Configurable options.
-
.method_missing(method, *args) ⇒ Object
rubocop:enable Style/OptionalBooleanParameter.
-
.respond_to_missing?(method, include_private = false) ⇒ Boolean
rubocop:disable Style/OptionalBooleanParameter.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#valid_mime_types=(value) ⇒ Object
Allows to set valid_mime_types to check against allowed mime types.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
48 49 50 51 |
# File 'lib/simple_images_downloader/configuration.rb', line 48 def initialize @destination = DEFAULT_DESTINATION @valid_mime_types = DEFAULT_VALID_MIME_TYPES end |
Class Method Details
.accessor?(method) ⇒ Boolean
91 92 93 |
# File 'lib/simple_images_downloader/configuration.rb', line 91 def self.accessor?(method) ACCESSORS.include?(method) end |
.configure {|config| ... } ⇒ Object
Configurable options
destination: String, default: ‘./’, description: ‘Destination folder to put downloaded images’ valid_mime_types: Array, default: [
'image/avif', 'image/gif', 'image/apng', 'image/jpg',
'image/jpeg', 'image/png', 'image/svg+xml', 'image/webp'
], description: ‘Valid mime types to download’
76 77 78 |
# File 'lib/simple_images_downloader/configuration.rb', line 76 def self.configure yield instance end |
.method_missing(method, *args) ⇒ Object
rubocop:enable Style/OptionalBooleanParameter
86 87 88 89 |
# File 'lib/simple_images_downloader/configuration.rb', line 86 def self.method_missing(method, *args) super unless accessor?(method.to_s.gsub(/=$/, '').to_sym) instance.public_send(method, *args) end |
.respond_to_missing?(method, include_private = false) ⇒ Boolean
rubocop:disable Style/OptionalBooleanParameter
81 82 83 |
# File 'lib/simple_images_downloader/configuration.rb', line 81 def self.respond_to_missing?(method, include_private = false) accessor?(method) || super end |
Instance Method Details
#valid_mime_types=(value) ⇒ Object
Allows to set valid_mime_types to check against allowed mime types
RFC 1341 - MIME (Multipurpose Internet Mail Extensions) format
59 60 61 62 63 |
# File 'lib/simple_images_downloader/configuration.rb', line 59 def valid_mime_types=(value) raise Errors::BaseError, 'valid_mime_types must be an array' unless value.is_a?(Array) @valid_mime_types = value end |