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

Class Method Summary collapse

Class Attribute Details

.configObject

The process-wide configuration, seeded from the environment (see Config). Set it up once at boot; it is read, not written, per URL.



36
37
38
# File 'lib/oximg/server.rb', line 36

def config
  @config ||= Config.new
end

Class Method Details

.configure {|config| ... } ⇒ Object

Yields:



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 options_url_for(source, **options)
  UrlBuilder.new(config).options(source, **options)
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, **options)
  UrlBuilder.new(config).resize(source, **options)
end