Class: Shrine::Derivation
- Inherits:
-
Object
- Object
- Shrine::Derivation
- Defined in:
- lib/shrine/plugins/derivation_endpoint.rb
Defined Under Namespace
Classes: Command, Delete, Generate, NotFound, Processed, Response, Retrieve, SourceNotFound, Upload, Url
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Class Method Summary collapse
Instance Method Summary collapse
-
#delete ⇒ Object
Deletes the derivation result from the storage.
-
#generate(file = nil) ⇒ Object
Calls the derivation block and returns the direct result.
-
#initialize(name:, args:, source:, options:) ⇒ Derivation
constructor
A new instance of Derivation.
-
#option(name) ⇒ Object
Retrieves the value of a derivation option.
-
#processed ⇒ Object
Returns the derivation result as a File/Tempfile or a Shrine::UploadedFile object.
-
#response(env) ⇒ Object
Returns the derivation result in form of a Rack response triple.
-
#retrieve ⇒ Object
Returns a Shrine::UploadedFile object pointing to the uploaded derivation result.
- #shrine_class ⇒ Object
-
#upload(file = nil) ⇒ Object
Uploads the derivation result to a dedicated destination on the specified Shrine storage.
-
#url(**options) ⇒ Object
Returns an URL to the derivation.
Constructor Details
#initialize(name:, args:, source:, options:) ⇒ Derivation
Returns a new instance of Derivation.
129 130 131 132 133 134 |
# File 'lib/shrine/plugins/derivation_endpoint.rb', line 129 def initialize(name:, args:, source:, options:) @name = name @args = args @source = source @options = end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
127 128 129 |
# File 'lib/shrine/plugins/derivation_endpoint.rb', line 127 def args @args end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
127 128 129 |
# File 'lib/shrine/plugins/derivation_endpoint.rb', line 127 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
127 128 129 |
# File 'lib/shrine/plugins/derivation_endpoint.rb', line 127 def @options end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
127 128 129 |
# File 'lib/shrine/plugins/derivation_endpoint.rb', line 127 def source @source end |
Class Method Details
.option(name, default: nil, result: nil) ⇒ Object
185 186 187 |
# File 'lib/shrine/plugins/derivation_endpoint.rb', line 185 def self.option(name, default: nil, result: nil) [name] = { default: default, result: result } end |
.options ⇒ Object
181 182 183 |
# File 'lib/shrine/plugins/derivation_endpoint.rb', line 181 def self. @options ||= {} end |
Instance Method Details
#delete ⇒ Object
Deletes the derivation result from the storage.
177 178 179 |
# File 'lib/shrine/plugins/derivation_endpoint.rb', line 177 def delete Derivation::Delete.new(self).call end |
#generate(file = nil) ⇒ Object
Calls the derivation block and returns the direct result.
160 161 162 |
# File 'lib/shrine/plugins/derivation_endpoint.rb', line 160 def generate(file = nil) Derivation::Generate.new(self).call(file) end |
#option(name) ⇒ Object
Retrieves the value of a derivation option.
-
If specified as a raw value, returns that value
-
If specified as a block, evaluates that it and returns the result
-
If unspecified, returns the default value
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/shrine/plugins/derivation_endpoint.rb', line 216 def option(name) option_definition = self.class..fetch(name) value = .fetch(name) { shrine_class.[name] } value = instance_exec(&value) if value.is_a?(Proc) if value.nil? default = option_definition[:default] value = instance_exec(&default) if default end result = option_definition[:result] value = instance_exec(value, &result) if result value end |
#processed ⇒ Object
Returns the derivation result as a File/Tempfile or a Shrine::UploadedFile object.
155 156 157 |
# File 'lib/shrine/plugins/derivation_endpoint.rb', line 155 def processed Derivation::Processed.new(self).call end |
#response(env) ⇒ Object
Returns the derivation result in form of a Rack response triple.
149 150 151 |
# File 'lib/shrine/plugins/derivation_endpoint.rb', line 149 def response(env) Derivation::Response.new(self).call(env) end |
#retrieve ⇒ Object
Returns a Shrine::UploadedFile object pointing to the uploaded derivation result.
172 173 174 |
# File 'lib/shrine/plugins/derivation_endpoint.rb', line 172 def retrieve Derivation::Retrieve.new(self).call end |
#shrine_class ⇒ Object
233 234 235 |
# File 'lib/shrine/plugins/derivation_endpoint.rb', line 233 def shrine_class source.shrine_class end |
#upload(file = nil) ⇒ Object
Uploads the derivation result to a dedicated destination on the specified Shrine storage.
166 167 168 |
# File 'lib/shrine/plugins/derivation_endpoint.rb', line 166 def upload(file = nil) Derivation::Upload.new(self).call(file) end |
#url(**options) ⇒ Object
Returns an URL to the derivation.
137 138 139 140 141 142 143 144 145 146 |
# File 'lib/shrine/plugins/derivation_endpoint.rb', line 137 def url(**) Derivation::Url.new(self).call( host: option(:host), prefix: option(:prefix), expires_in: option(:expires_in), version: option(:version), metadata: option(:metadata), **, ) end |