Class: Tanshuku::Configuration
- Inherits:
-
Object
- Object
- Tanshuku::Configuration
- Includes:
- ActiveModel::Attributes
- Defined in:
- lib/tanshuku/configuration.rb
Overview
A class for managing Tanshuku configurations.
Defined Under Namespace
Modules: DefaultExceptionReporter, DefaultKeyGenerator, DefaultUrlHasher
Instance Attribute Summary collapse
-
#default_url_options ⇒ Hash, void
Default URL options for Rails’
url_for
. -
#exception_reporter ⇒ #call, void
A error-reporter class, module, or object used when shortening a URL fails.
-
#key_generator ⇒ #call, void
A class, module, or object to generate a unique key for shortened URLs.
-
#key_length ⇒ Integer, void
Length of Url#key when #key_generator is DefaultKeyGenerator.
-
#max_url_length ⇒ Integer, void
Maximum length of Url#url.
-
#url_hasher ⇒ #call, void
A class, module, or object to hash a URL.
-
#url_pattern ⇒ Regexp, void
Allowed pattern of Url#url.
Instance Method Summary collapse
-
#configure {|config| ... } ⇒ void
private
Configures Tanshuku thread-safely.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
174 175 176 177 |
# File 'lib/tanshuku/configuration.rb', line 174 def initialize(...) super @mutex = Mutex.new end |
Instance Attribute Details
#default_url_options ⇒ Hash, void
The example below means that the configured host and protocol are used. Shortened URLs will be like https://example.com/t/abcdefghij0123456789
.
Default URL options for Rails’ url_for
. Defaults to {}.
62 |
# File 'lib/tanshuku/configuration.rb', line 62 attribute :default_url_options, default: {} |
#exception_reporter ⇒ #call, void
The example below means that an exception and a URL will be reported to Sentry (sentry.io).
A error-reporter class, module, or object used when shortening a URL fails. This should respond to #call
with required keyword arguments exception:
and original_url:
. Defaults to DefaultExceptionReporter.
172 |
# File 'lib/tanshuku/configuration.rb', line 172 attribute :exception_reporter, default: DefaultExceptionReporter |
#key_generator ⇒ #call, void
The example below means that unique keys for shortened URLs are generated by SecureRandom.uuid
.
A class, module, or object to generate a unique key for shortened URLs. This should respond to #call
without any arguments. Defaults to DefaultKeyGenerator.
150 |
# File 'lib/tanshuku/configuration.rb', line 150 attribute :key_generator, default: DefaultKeyGenerator |
#key_length ⇒ Integer, void
Don’t forget to fix the limit of the tanshuku_urls.key
column if you change this value.
The example below means that Url#key has 10-char string.
Length of Url#key when #key_generator is DefaultKeyGenerator. Defaults to 20
.
115 |
# File 'lib/tanshuku/configuration.rb', line 115 attribute :key_length, :integer, default: 20 |
#max_url_length ⇒ Integer, void
79 |
# File 'lib/tanshuku/configuration.rb', line 79 attribute :max_url_length, :integer, default: 10_000 |
#url_hasher ⇒ #call, void
The example below means that URLs are hashed with Digest::SHA256.hexdigest
.
A class, module, or object to hash a URL. This should respond to #call
with a required positional argument url
and a required keyword argument namespace:
. Defaults to DefaultUrlHasher.
133 |
# File 'lib/tanshuku/configuration.rb', line 133 attribute :url_hasher, default: DefaultUrlHasher |
#url_pattern ⇒ Regexp, void
96 |
# File 'lib/tanshuku/configuration.rb', line 96 attribute :url_pattern, default: %r{\A(?:https?://\w+|/)} |
Instance Method Details
#configure {|config| ... } ⇒ void
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.
Use Tanshuku.configure as a public API for configuration.
This method returns an undefined value.
Configures Tanshuku thread-safely.
189 190 191 192 193 |
# File 'lib/tanshuku/configuration.rb', line 189 def configure @mutex.synchronize do yield self end end |