Class: Shrine::Derivation
- Inherits:
-
Object
- Object
- Shrine::Derivation
- Defined in:
- lib/shrine/plugins/derivation_endpoint.rb
Defined Under Namespace
Classes: Command, Delete, Generate, NotFound, Opened, 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.
-
#opened ⇒ Object
Returns opened Shrine::UploadedFile object pointing to the uploaded derivative if it exists.
-
#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 derivative if it exists.
- #shrine_class ⇒ Object
-
#upload(file = nil, **options) ⇒ 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.
124 125 126 127 128 129 |
# File 'lib/shrine/plugins/derivation_endpoint.rb', line 124 def initialize(name:, args:, source:, options:) @name = name.to_sym @args = args @source = source = end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
122 123 124 |
# File 'lib/shrine/plugins/derivation_endpoint.rb', line 122 def args @args end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
122 123 124 |
# File 'lib/shrine/plugins/derivation_endpoint.rb', line 122 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
122 123 124 |
# File 'lib/shrine/plugins/derivation_endpoint.rb', line 122 def end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
122 123 124 |
# File 'lib/shrine/plugins/derivation_endpoint.rb', line 122 def source @source end |
Class Method Details
.option(name, default: nil, result: nil) ⇒ Object
186 187 188 |
# File 'lib/shrine/plugins/derivation_endpoint.rb', line 186 def self.option(name, default: nil, result: nil) [name] = { default: default, result: result } end |
.options ⇒ Object
182 183 184 |
# File 'lib/shrine/plugins/derivation_endpoint.rb', line 182 def self. ||= {} end |
Instance Method Details
#delete ⇒ Object
Deletes the derivation result from the storage.
178 179 180 |
# File 'lib/shrine/plugins/derivation_endpoint.rb', line 178 def delete Derivation::Delete.new(self).call end |
#generate(file = nil) ⇒ Object
Calls the derivation block and returns the direct result.
155 156 157 |
# File 'lib/shrine/plugins/derivation_endpoint.rb', line 155 def generate(file = nil) Derivation::Generate.new(self).call(file) end |
#opened ⇒ Object
Returns opened Shrine::UploadedFile object pointing to the uploaded derivative if it exists.
173 174 175 |
# File 'lib/shrine/plugins/derivation_endpoint.rb', line 173 def opened Derivation::Opened.new(self).call 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
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/shrine/plugins/derivation_endpoint.rb', line 215 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.
150 151 152 |
# File 'lib/shrine/plugins/derivation_endpoint.rb', line 150 def processed Derivation::Processed.new(self).call end |
#response(env) ⇒ Object
Returns the derivation result in form of a Rack response triple.
144 145 146 |
# File 'lib/shrine/plugins/derivation_endpoint.rb', line 144 def response(env) Derivation::Response.new(self).call(env) end |
#retrieve ⇒ Object
Returns a Shrine::UploadedFile object pointing to the uploaded derivative if it exists.
167 168 169 |
# File 'lib/shrine/plugins/derivation_endpoint.rb', line 167 def retrieve Derivation::Retrieve.new(self).call end |
#shrine_class ⇒ Object
232 233 234 |
# File 'lib/shrine/plugins/derivation_endpoint.rb', line 232 def shrine_class source.shrine_class end |
#upload(file = nil, **options) ⇒ Object
Uploads the derivation result to a dedicated destination on the specified Shrine storage.
161 162 163 |
# File 'lib/shrine/plugins/derivation_endpoint.rb', line 161 def upload(file = nil, **) Derivation::Upload.new(self).call(file, **) end |
#url(**options) ⇒ Object
Returns an URL to the derivation.
132 133 134 135 136 137 138 139 140 141 |
# File 'lib/shrine/plugins/derivation_endpoint.rb', line 132 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 |