Method: Refile::BackendMacros#verify_uploadable

Defined in:
lib/refile/backend_macros.rb

#verify_uploadable(method) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/refile/backend_macros.rb', line 20

def verify_uploadable(method)
  mod = Module.new do
    define_method(method) do |uploadable|
      [:size, :read, :eof?, :rewind, :close].each do |m|
        unless uploadable.respond_to?(m)
          raise Refile::InvalidFile, "does not respond to `#{m}`."
        end
      end
      if max_size and uploadable.size > max_size
        raise Refile::InvalidMaxSize, "#{uploadable.inspect} is too large"
      end
      super(uploadable)
    end
  end
  prepend mod
end