Module: Shrine::Plugins::DerivationEndpoint::ClassMethods
- Defined in:
- lib/shrine/plugins/derivation_endpoint.rb
Instance Method Summary collapse
-
#derivation(name, &block) ⇒ Object
Registers a derivation block, which is called when the corresponding derivation URL is requested.
-
#derivation_endpoint(**options) ⇒ Object
Returns a mountable Rack app that handles derivation requests.
- #derivation_options ⇒ Object
-
#derivation_response(env, **options) ⇒ Object
Calls the derivation endpoint passing the request information, and returns the Rack response triple.
- #derivations ⇒ Object
Instance Method Details
#derivation(name, &block) ⇒ Object
Registers a derivation block, which is called when the corresponding derivation URL is requested.
78 79 80 |
# File 'lib/shrine/plugins/derivation_endpoint.rb', line 78 def derivation(name, &block) derivations[name] = block end |
#derivation_endpoint(**options) ⇒ Object
Returns a mountable Rack app that handles derivation requests.
46 47 48 |
# File 'lib/shrine/plugins/derivation_endpoint.rb', line 46 def derivation_endpoint(**) Shrine::DerivationEndpoint.new(shrine_class: self, options: ) end |
#derivation_options ⇒ Object
86 87 88 |
# File 'lib/shrine/plugins/derivation_endpoint.rb', line 86 def opts[:derivation_endpoint_options] end |
#derivation_response(env, **options) ⇒ Object
Calls the derivation endpoint passing the request information, and returns the Rack response triple.
It uses a trick where it removes the derivation path prefix from the path info before calling the Rack app, which is what web framework routers do before they’re calling a mounted Rack app.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/shrine/plugins/derivation_endpoint.rb', line 56 def derivation_response(env, **) script_name = env["SCRIPT_NAME"] path_info = env["PATH_INFO"] prefix = [:prefix] match = path_info.match(/^\/#{prefix}/) fail Error, "request path must start with \"/#{prefix}\", but is \"#{path_info}\"" unless match begin env["SCRIPT_NAME"] += match.to_s env["PATH_INFO"] = match.post_match derivation_endpoint(**).call(env) ensure env["SCRIPT_NAME"] = script_name env["PATH_INFO"] = path_info end end |
#derivations ⇒ Object
82 83 84 |
# File 'lib/shrine/plugins/derivation_endpoint.rb', line 82 def derivations opts[:derivation_endpoint_derivations] end |