Module: Oximg::Server
- Defined in:
- lib/oximg/server.rb,
lib/oximg/server/config.rb,
lib/oximg/server/signer.rb,
lib/oximg/server/url_builder.rb
Overview
The remote half of oximg: building — and HMAC-signing — URLs for an
oximg server, for deployments that let the server do the work
instead of processing locally with Oximg.resize.
Oximg::Server.configure do |config|
config.endpoint = "https://img.example.com"
config.key = ENV["OXIMG_KEY"]
config.salt = ENV["OXIMG_SALT"]
end
Oximg::Server.url_for("photos/a.jpg", width: 750)
#=> "https://img.example.com/{sig}/resize/750/0/photos/a.jpg"
Nothing here talks to the server: a URL is arithmetic over the config, so a view can emit thousands of them without leaving the process.
Defined Under Namespace
Modules: Signer Classes: Config, ConfigurationError, UrlBuilder
Class Attribute Summary collapse
-
.config ⇒ Object
The process-wide configuration, seeded from the environment (see Config).
Class Method Summary collapse
- .configure {|config| ... } ⇒ Object
-
.options_url_for(source, **options) ⇒ Object
The Cloudflare-Images-style options route: see UrlBuilder#options.
-
.reset! ⇒ Object
Drops the configuration back to the environment defaults.
-
.url_for(source, **options) ⇒ Object
The positional route: see UrlBuilder#resize.
Class Attribute Details
Class Method Details
.configure {|config| ... } ⇒ Object
42 43 44 45 |
# File 'lib/oximg/server.rb', line 42 def configure yield config config end |
.options_url_for(source, **options) ⇒ Object
The Cloudflare-Images-style options route: see UrlBuilder#options.
60 61 62 |
# File 'lib/oximg/server.rb', line 60 def (source, **) UrlBuilder.new(config).(source, **) end |
.reset! ⇒ Object
Drops the configuration back to the environment defaults. Exists for tests — an app should configure once at boot.
49 50 51 |
# File 'lib/oximg/server.rb', line 49 def reset! @config = Config.new end |
.url_for(source, **options) ⇒ Object
The positional route: see UrlBuilder#resize.
54 55 56 |
# File 'lib/oximg/server.rb', line 54 def url_for(source, **) UrlBuilder.new(config).resize(source, **) end |