Module: Adrift::FileToAttach

Defined in:
lib/adrift/file_to_attach.rb

Overview

Factory of the objects that Attachment#assign expects. Theese are adapters for the Rack and Rails’ uploaded file representations and File instances.

Defined Under Namespace

Modules: Adapter, Adapters

Class Method Summary collapse

Class Method Details

.new(file_representation) ⇒ Object

Creates a new object that will that will act as an adapter for file_representation, the object that represents the file to be attached. This adapter wil have the interface expected by Attachment#assign.

Raises Adrift::UnknownFileRepresentationError when it can’t recognize file_representation.



98
99
100
101
102
# File 'lib/adrift/file_to_attach.rb', line 98

def self.new(file_representation)
  adapter_class = find_adapter_class(file_representation)
  raise UnknownFileRepresentationError if adapter_class.nil?
  adapter_class.new(file_representation)
end