Sha256: 2bf006fe05149205cf85e4a19706af168db04be2e14e52b5cae2624480b722b6
Contents?: true
Size: 924 Bytes
Versions: 3
Compression:
Stored size: 924 Bytes
Contents
module Refile # Macros which make it easier to write secure backends. # # @api private module BackendMacros def verify_id(method) mod = Module.new do define_method(method) do |id| id = id.to_s if id =~ /\A[a-z0-9]+\z/i super(id) else raise Refile::InvalidID end end end prepend mod end def verify_uploadable(method) mod = Module.new do define_method(method) do |uploadable| [:size, :read, :eof?, :close].each do |m| unless uploadable.respond_to?(m) raise ArgumentError, "does not respond to `#{m}`." end end if max_size and uploadable.size > max_size raise Refile::Invalid, "#{uploadable.inspect} is too large" end super(uploadable) end end prepend mod end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
refile-0.5.5 | lib/refile/backend_macros.rb |
refile-0.5.4 | lib/refile/backend_macros.rb |
refile-0.5.3 | lib/refile/backend_macros.rb |