Class: Shrine::Plugins::Transloadit::TransloaditFile

Inherits:
Object
  • Object
show all
Defined in:
lib/shrine/plugins/transloadit.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(transloadit:, steps: [], multiple: nil) ⇒ TransloaditFile

Returns a new instance of TransloaditFile.



343
344
345
346
347
# File 'lib/shrine/plugins/transloadit.rb', line 343

def initialize(transloadit:, steps: [], multiple: nil)
  @transloadit = transloadit
  @steps       = steps
  @multiple    = multiple
end

Instance Attribute Details

#stepsObject (readonly)

Returns the value of attribute steps.



341
342
343
# File 'lib/shrine/plugins/transloadit.rb', line 341

def steps
  @steps
end

#transloaditObject (readonly)

Returns the value of attribute transloadit.



341
342
343
# File 'lib/shrine/plugins/transloadit.rb', line 341

def transloadit
  @transloadit
end

Instance Method Details

#add_step(*args) ⇒ Object

Adds a step to the pipeline, automatically setting :use to the previous step, so that later multiple pipelines can be seamlessly joined into a single assembly.

It returns a new TransloaditFile with the step added.



354
355
356
357
358
359
360
361
362
363
364
365
366
# File 'lib/shrine/plugins/transloadit.rb', line 354

def add_step(*args)
  if args[0].is_a?(::Transloadit::Step)
    step = args[0]
  else
    step = transloadit.step(*args)
  end

  unless step.options[:use]
    step.use steps.last if steps.any?
  end

  transloadit_file(steps: steps + [step])
end

#exported?Boolean

Returns true if this TransloaditFile includes an export step.

Returns:

  • (Boolean)


394
395
396
# File 'lib/shrine/plugins/transloadit.rb', line 394

def exported?
  @steps.any? && @steps.last.robot.end_with?("/store")
end

#imported?Boolean

Returns true if this TransloaditFile includes an import step.

Returns:

  • (Boolean)


389
390
391
# File 'lib/shrine/plugins/transloadit.rb', line 389

def imported?
  @steps.any? && @steps.first.robot.end_with?("/import")
end

#multiple(format = nil) ⇒ Object

Specify the result format.



369
370
371
372
373
374
375
# File 'lib/shrine/plugins/transloadit.rb', line 369

def multiple(format = nil)
  if format
    transloadit_file(multiple: format)
  else
    @multiple
  end
end

#nameObject

The key that Transloadit will use in its processing results for the corresponding processed file. This equals to the name of the last step, unless the last step is an export step.



380
381
382
383
384
385
386
# File 'lib/shrine/plugins/transloadit.rb', line 380

def name
  if exported?
    @steps[-2].name
  else
    @steps.last.name
  end
end