Methods
Public Instance
Public Instance methods
derivation(name, &block)
Registers a derivation block, which is called when the corresponding derivation URL is requested.
[show source]
# File lib/shrine/plugins/derivation_endpoint.rb 73 def derivation(name, &block) 74 derivations[name.to_sym] = block 75 end
derivation_endpoint(**options)
Returns a mountable Rack app that handles derivation requests.
[show source]
# File lib/shrine/plugins/derivation_endpoint.rb 41 def derivation_endpoint(**options) 42 Shrine::DerivationEndpoint.new(shrine_class: self, options: options) 43 end
derivation_options()
[show source]
# File lib/shrine/plugins/derivation_endpoint.rb 81 def derivation_options 82 opts[:derivation_endpoint][:options] 83 end
derivation_response(env, **options)
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.
[show source]
# File lib/shrine/plugins/derivation_endpoint.rb 51 def derivation_response(env, **options) 52 script_name = env["SCRIPT_NAME"] 53 path_info = env["PATH_INFO"] 54 55 prefix = derivation_options[:prefix] 56 match = path_info.match(/^\/#{prefix}/) 57 58 fail Error, "request path must start with \"/#{prefix}\", but is \"#{path_info}\"" unless match 59 60 begin 61 env["SCRIPT_NAME"] += match.to_s 62 env["PATH_INFO"] = match.post_match 63 64 derivation_endpoint(**options).call(env) 65 ensure 66 env["SCRIPT_NAME"] = script_name 67 env["PATH_INFO"] = path_info 68 end 69 end
derivations()
[show source]
# File lib/shrine/plugins/derivation_endpoint.rb 77 def derivations 78 opts[:derivation_endpoint][:derivations] 79 end